如何使用 check_box_tag 在 Haml 中选中复选框 [英] How to check a check box in Haml using check_box_tag
本文介绍了如何使用 check_box_tag 在 Haml 中选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉我如何将这些复选框设置为选中状态?我确定这很简单,但经过一个小时的尝试后,我想我需要问一下!谢谢!
Can someone tell me how to set these check boxes to checked? I'm sure it's simple, but after an hour of trying i think I need to ask! Thanks!
= form_tag movies_path, :id => 'ratings_form', :method => :get do
Include:
- @all_ratings.each do |rating|
= rating
= check_box_tag "ratings[#{rating}]",
= submit_tag 'Refresh', :id => 'ratings_submit'
推荐答案
Ref check_box_tag
check_box_tag "ratings[#{rating}]", 1, !!(rating.rating)
您的第二个参数
必须是复选框的value
您的 第三个参数
必须是一个 boolean 条件
,它返回 true/false
并取决于它复选框是 checked/unchecked代码>
Your 3rd parameter
must be a boolean condition
which return true/false
and depends on it checkbox is checked/unchecked
这篇关于如何使用 check_box_tag 在 Haml 中选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文