【问题标题】:Get specific input value in custom helper在自定义助手中获取特定的输入值
【发布时间】:2014-05-29 10:12:58
【问题描述】:

我已经创建了帮助器以我想要的方式打印输入,目前的方法如下所示:

  def code_input(builder, method, is_disabled)

    builder.input method.to_sym, as: :string, label: t("activerecord.attributes.#{builder.object_name}.#{method}"),
                  input_html: { class: 'input-medium', value: is_disabled ? '*****' : builder.object.method, disabled: is_disabled }
  end

如果is_disabledfalse,我遇到的问题是输入值。 Rails 打印出这样的错误:

wrong number of arguments(0 for 1)

这样的用法:

= code_input(f, :random_code, @code.locked)

但是,如果我直接在表单中执行此操作,而不是通过这样的助手:f.object.random_code 我得到正确的值而没有错误...您能否向我解释我做错了什么我正在使用 formtastic 和 Rails 3.

【问题讨论】:

    标签: ruby-on-rails formtastic


    【解决方案1】:

    我通过以下方式实现了我想要的:

    builder.input method.to_sym, as: :string, label: t("activerecord.attributes.#{builder.object_name}.#{method}"),
                  input_html: { class: 'input-medium', value: is_disabled ? '*****' : builder.object.attributes["#{method}"], disabled: is_disabled }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      相关资源
      最近更新 更多