SaaS课程中的另一个经过一些试验并且只有错误。有一个电影表可以过滤(通过复选框)并按评级排序(通过点击图标)。如果已过滤,则后续排序应保留过滤器。
我想'link_to'触发的请求应该包含_path()中的'rating'参数,这样控制器就可以查询并提交相应的视图。
如果这是对的 - 如何在movies_path()中获取check_box_tag值?如果没有,我该怎么办?提前谢谢!
%h1 All Movies
=puts 'Ratings: ', params[:ratings].nil?
= form_tag movies_path, :id => 'ratings_form', :method => :get do
Include:
- @all_ratings.each do |rating|
= rating
= check_box_tag "ratings[#{rating}]", 1, @filtered_ratings.include?(rating) ? true : false
= submit_tag 'Refresh', :id => 'ratings_submit'
%table#movies
%thead
%tr
%th{:class => @title_header}= link_to "Movie Title", movies_path(:sort => "title"), :id => 'title_header'
%th Rating
%th{:class => @date_header}= link_to "Release Date", movies_path(:sort => "release_date"), :id=> 'release_date_header'
%th More Info
%tbody
答案 0 :(得分:1)
所以我了解到,可以简单地将params[]
中的元素添加到_path(),以便它们显示在由?
分隔的URL中。希望这对其他初学者有用..
%thead
%tr
%th{:class => @title_header}= link_to "Movie Title", movies_path(:sort => "title", :ratings => params[:ratings]), :id => 'title_header'
%th Rating
%th{:class => @date_header}= link_to "Release Date", movies_path(:sort => "release_date", :ratings => params[:ratings]), :id=> 'release_date_header'
%th More Info
%tbody