I’m trying to create a nested form but I’m missing something as keep getting an error.
–configuration model
class Configuration < ActiveRecord::Base
has_many :configoptions
accepts_nested_attributes_for :configoptions
end
–show configuration view
<%= form_for @config do |f| %>
<%= f.fields_for :configoptions do |fp| %>
<p>
<%= fp.label :name %>
<%= fp.text_field :name %>
</p>
<% end %>
<%= f.submit %>
<% end %>
According to some online guides i’ve found this should work. but I keep getting an error:
undefined method `configuration_path' for #<#<Class:0x2549dac>:0x2548f88>
Does anyone know a way to make this work?
Thanks a lot!
It seems your routes are configured incorrectly. The following line:
creates a form tag to post your new/updated object to. In this case, it would look for
configuration_pathas the default path for a new object form. Userake routesto see if there is a listing similar to thisor look for
resources :configurationsin yourconfig/routes.rb. (If not, addresource :configurations). If you get confused by routing, check out the corresponding Rails Guide:http://guides.rubyonrails.org/routing.html
Alternatively, you can specify a different URL to post the action to, by passing the
:urlargument to your form helper: