【问题标题】:Formtastic default values on specific controller actions特定控制器操作的格式默认值
【发布时间】:2015-08-12 23:15:06
【问题描述】:

我目前拥有的是一个看起来像这样的表单:

form do |f|
  f.semantic_errors*f.object.errors.keys
  f.inputs "Book Details" do
  f.input :id
  f.input :name
  f.input :min_quantity, hint: "usually 3", input_html: {value: 3}
end

我遇到了f.input :min_quantity, hint: "usually 3", input_html: {value: 3} 的问题 创建新书时,我希望表单将 min_quantity 默认为 3,它现在就是这样做的。但是,当我以后更新这本书时,该字段将在 CMS 中自动设置为 3,并覆盖之前的内容。

所以我的问题是,是否有办法仅在 create 操作中使用 input_html: {value: 3} 而不是在 update 中使用它

【问题讨论】:

    标签: ruby-on-rails forms activeadmin formtastic


    【解决方案1】:
    f.input :min_quantity, hint: "usually 3", f.object.new_record? : {input_html: {value: 3}} : {}
    

    【讨论】:

      猜你喜欢
      • 2016-04-03
      • 2013-06-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多