rails 复选框 check_box_tag

  1. <%= error_messages_for 'product' %>  
  2.   
  3. <p>  
  4.   Name<br/>  
  5.   <%= text_field :product, :name %>  
  6. </p>  
  7.   
  8. <p>  
  9.   Price<br/>  
  10.   <%= text_field :product, :price %>  
  11. </p>  
  12.   
  13. <p>  
  14.   <% for category in Category.find(:all) %>  
  15.   <div>  
  16.     <%= check_box_tag "product[category_ids][]", category.id, @product.categories.include?(category) %>  
  17.     <%= category.name %>  
  18.   </div>  
  19.   <% end %>  
  20. </p>  



check_box_tag 'accept'
# => <input id="accept" name="accept" type="checkbox" value="1" />

check_box_tag 'rock', 'rock music'
# => <input id="rock" name="rock" type="checkbox" value="rock music" />

check_box_tag 'receive_email', 'yes', true
# => <input checked="checked" id="receive_email" name="receive_email" type="checkbox" value="yes" />

check_box_tag 'tos', 'yes', false, class: 'accept_tos'
# => <input class="accept_tos" id="tos" name="tos" type="checkbox" value="yes" />

check_box_tag 'eula', 'accepted', false, disabled: true
# => <input disabled="disabled" id="eula" name="eula" type="checkbox" value="accepted" />

通过 value 的值可判断check_box是否存在

你可能感兴趣的:(rails 复选框 check_box_tag)