如何使用check_box_tag检查Haml中的复选框 [英] How to check a check box in Haml using check_box_tag

查看:131
本文介绍了如何使用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)

您的第二个参数必须为的复选框

您的第三个参数必须是布尔条件,它返回 true / false 并依赖于它复选框已选中/未选中

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆