2

@tech_data = TagNode.first outputs below object from the controller .

p @tech_data
#<TagNode _id: 5119dcf74054448e576f3392, parent_id: nil, parent_ids: [], name: "categories", path: "categories", _type: "TagNode">

I have a form which has the fields name, _type, and category. But my object doesn't have the field category.

Here's my form

  = 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"

My form has an additional field that my object doesn't have. I get an error when the form is loaded, as I don't have category field in my object.

How can I select the category value in the form without adding this field to the model?

admdrew
  • 3,790
  • 4
  • 27
  • 39
user3636388
  • 187
  • 2
  • 24

1 Answers1

0

You need something like attr_accessor in Ruby,What is attr_accessor in Ruby? Please include following in your model,which will make to get values from form to controller. attr_accessor :category

Community
  • 1
  • 1
Manoj Menon
  • 1,028
  • 8
  • 18