【问题标题】:Rails - Add class if Radio button is checkedRails - 如果选中单选按钮,则添加类
【发布时间】:2014-07-07 00:12:23
【问题描述】:

如何从 form_for 助手中获取单选按钮的值?

使用 SLIM。

=form_for(@foo) do |f|
  label[class="#{ f.type.value == 'type 1'? 'foo' : 'bar'}"]
    | Type 1
    = f.radio_button :type, 'Type 1' 
  label[class="#{ f.type.value == 'type 2'? 'foo' : 'bar'}"]
    | Type 2
    = f.radio_button :type, 'Type 2' 

值方法不存在。如何访问表单助手的radio方法的值?

【问题讨论】:

  • 你阅读过 Rails 文档吗?
  • @emaillenin 没有提到访问值Rails
  • 有人吗?..真的需要这个..

标签: ruby-on-rails radio-button form-for slim-lang form-helpers


【解决方案1】:

根据this question,您也许可以使用实际的@foo 变量:

label[class="#{ @foo.type == 'type_2'? 'foo' : 'bar'}"]

【讨论】:

    猜你喜欢
    • 2017-07-13
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多