I have a complex model backed form and want to include multiple objects into my params.
My setup:
Network.rb
class Network < ActiveRecord::Base # t.string "name"
has_many :trackings
has_many :installations, through: :trackings
end
Installation.rb
class Installation < ActiveRecord::Base # t.string "name"
has_many :trackings
has_many :networks, through: :trackings
end
Tracking.rb
class Tracking < ActiveRecord::Base # t.string "code
belongs_to :network # t.integer "network_id",
belongs_to :installation # t.integer "installation_id
end
When I create a new Tracking-Object, I want to render each Network in the database and add a textfield for :code
My form:
= form_for [:admin, @tracking] do |f|
= f.select :installation_id, options_for_select(Installation.all.map { |i| [i.name, i.id] }), prompt: "Select an Installation"
- Network.all.each do |network|
= f.text_field :code
= f.submit
Currently all text fields get rendered but when I submit, only the last input of the last text field gets into my params. How can I include ALL of them?
For non model-backed form I found this, but it's not working for my form:
= text_field_tag "tracking[][code]"