如何在使用check_box_tag时默认选中复选框?

时间:2013-02-08 12:24:06

标签: html ruby-on-rails haml

= form_tag movies_path, :id => 'ratings_form', :method => :get do

  Include:

  - @all_ratings.each do |rating|
    = rating
    - is_checked = (!@selected_ratings.nil? && @selected_ratings.include?(rating))
    = check_box_tag "ratings[#{rating}]", is_checked, is_checked, {:id => "ratings_#{rating}"}
    = submit_tag 'Refresh', :id => 'ratings_submit'

1 个答案:

答案 0 :(得分:1)

参考: - check_box_tag

更改

check_box_tag "ratings[#{rating}]", is_checked, is_checked, {:id => "ratings_#{rating}"}

check_box_tag "ratings[#{rating}]", is_checked, true, {:id => "ratings_#{rating}"}