1

另一个来自 SaaS 课程的课程经过多次尝试和错误。有一个表格,其中包含可以过滤(通过复选框)和按评级排序(通过单击 theader)的电影。如果过滤,后续排序应保留过滤器。

我猜“link_to”触发的请求应该在 _path() 中包含“ratings”参数,以便控制器可以查询并提交相应的视图。

如果这是正确的 - 我如何在 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
4

1 回答 1

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
于 2013-01-31T04:59:39.840 回答