我对 ruby on rails 很陌生……我的问题是从复选框中获取输出。如果复选框是false
,我想显示每场音乐会,但我总是得到 else 条件......如何获得@concerts = Concert.find(:all, :order => "day")
标准输出,如果 check_box 被选中,得到 else 条件?
#index.html.erb
check_box('dm', false, options = {}, checked_value = "1", unchecked_value = "0")
# controller.rb
def index
if params[:dm] == '0'
@concerts = Concert.find(:all, :order => "day")
else
@concerts = Concert.find(:all, :order => "day", :conditions => {:bool => false})
end
开发日志
在 2012-08-14 13:21:39 +0200 开始 GET "/" for 127.0.0.1 由 ConcertsController#index 处理为 HTML [1m[36mConcert Load (0.0ms)[0m [1mSELECT concerts
.* FROM concerts
WHERE concerts
. bool
= 0 ORDER BY day[0m [1m[35mConcert Load (15.6ms)[0m SELECT concerts
.* FROM concerts
ORDER BY lineup [1m[36mConcert Load (0.0ms)[0m [1mSELECT DISTINCT day FROM concerts
ORDER BY day[0m [1m[35mConcert加载 (0.0ms)[0m SELECT DISTINCT club_id FROM concerts
... 在布局/应用程序中渲染的 Concerts/index.html.erb (78.0ms) 在 94ms 内完成 200 OK (查看次数: 78.0ms | ActiveRecord: 15.6ms)