【发布时间】:2015-01-17 03:20:22
【问题描述】:
@tech_data = TagNode.first 从控制器输出下面的对象。
p @tech_data
#<TagNode _id: 5119dcf74054448e576f3392, parent_id: nil, parent_ids: [], name: "categories", path: "categories", _type: "TagNode">
我有一个包含name、_type 和category 字段的表单。但我的对象没有 category 字段。
这是我的表格
= simple_form_for @tech_data, as: :techtags, :url => view_techtags_technologies_path, :remote => true,:method => :get,:html => {:id => "upsert_techtags",:data => {:spinner => "#tech-ui"}} do |f|
%label.pull-left Type
= f.input :_type, :collection => tech_types, :label => false, :input_html => {:class =>"chzn-select", :data => {:placeholder => "Select Technology Type"}, :multiple => false}
%label.pull-left Name
= f.input :name, :type=>"text", :required => true, :label => false, :placeholder =>"Type the New Technology", :input_html => {:style => "width:265px;margin-bottom:0;"}
%label.pull-left Category
= f.input :category, :collection => [1,2,3,4], :label => false, :input_html => {:class =>"chzn-select", :disabled=>"true",:data => {:placeholder => "Type or select category"}, :multiple => false}
= f.submit "Create", :class => "btn btn-primary pull-right"
我的表单有一个我的对象没有的附加字段。加载表单时出现错误,因为我的对象中没有 category 字段。
如何在表单中选择category 值而不将此字段添加到模型中?
【问题讨论】:
标签: ruby-on-rails ruby haml simple-form