我知道可能有 1 或 2 个类似的问题,但没有一个能帮助我理解我在下面的错误所在。在我看来,我有以下 haml 形式:
= form_tag movies_path,:id=>"ratings_form", :method => :get do
Include:
- @all_ratings.each_with_index do |rating, index|
= rating
= check_box_tag "ratings[]", rating, @selected_ratings.include?(rating), id:"ratings_#{rating}"
在我的控制器中:
def index
sorting=params[:sorting_on_a_column]
if sorting=='1'
@sort='title'
@movies=Movie.order('title')
elsif sorting=='2'
@sort='date'
@movies=Movie.order('release_date')
else
@movies=Movie.all
end
@all_ratings=Movie.select(:rating).map(&:rating).uniq
@selected_ratings = (params["ratings"].present? ? params["ratings"] : @all_ratings)
@movies = @movies.where(":rating IN (?)", params["ratings"]) if params["ratings"].present? and params["ratings"].any?
end
我在上面的目标是按标题或 release_date(它确实)对电影进行排序,并且只显示与选中的复选框相对应的电影。我是 Ruby 和 Rails 的新手,所以我非常感谢你的帮助。谢谢进步!