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
开发者_如何学Python<%= 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:
<%= form_for @config do |f| %>
creates a form tag to post your new/updated object to. In this case, it would look for configuration_path
as the default path for a new object form. Use rake routes
to see if there is a listing similar to this
configurations GET /configurations(.:format) {:action=>"index", :controller=>"configurations"}
POST /configurations(.:format) {:action=>"create", :controller=>"configurations"}
or look for resources :configurations
in your config/routes.rb
. (If not, add resource :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 :url
argument to your form helper:
<%= form_for @config, :url => some_other_path do |f| %>
精彩评论