加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails 3.有条件地用Formtastic显示字段

发布时间:2020-12-16 22:14:35 所属栏目:百科 来源:网络整理
导读:我正在使用ActiveAdmin和Formtastic. 我有一张发票单,有一个出货单的下拉菜单. form do |f| f.inputs "Shipment Details" do f.input :shipment_id,:label = "Shipment",:as = :select,:collection = Shipment.find(invoiceless_shipments,:order = "file_nu
我正在使用ActiveAdmin和Formtastic.

我有一张发票单,有一个出货单的下拉菜单.

form do |f|
  f.inputs "Shipment Details" do      
  f.input :shipment_id,:label => "Shipment",:as => :select,:collection => Shipment.find(invoiceless_shipments,:order => "file_number",:select => "id,file_number").map{|v| [v.file_number,v.id] }
  f.input :issued_at,:label => "Date",:as => :datepicker
  ... more fields ...
end

如果表单是新发票表单,我只想显示出货的选择菜单.

如果表单是编辑表单,我不想显示出货下拉菜单.因此,如果表单是编辑表单,则不会更改.

我正在考虑做一些类似的事情

if params[:action] != 'edit'
  f.input :shipment_id,:as => :select...
end

但我收到DSL错误.

解决方法

尝试
form do |f|
  f.inputs "Shipment Details" do      
    if f.object.new_record?
        f.input :shipment_id,:as => :select...
    end
    ...
  end
end

问题(部分)在这里提到:Accessing object of form in formtastic

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读