What is the form_for syntax for nested resources?
Posted
by Kris
on Stack Overflow
See other posts from Stack Overflow
or by Kris
Published on 2010-03-18T11:24:01Z
Indexed on
2010/03/18
11:51 UTC
Read the original article
Hit count: 313
rails
|ruby-on-rails
I am trying to create a form for a nested resource. Here is my route:
map.resources :websites do |website|
website.resources :domains
end
Here are my attempts and the errors:
<% form_for(@domain, :url => website_domains_path(@website)) do | form | %>
<%= form.text_field :name %>
# ArgumentError: wrong number of arguments (1 for 0)
# form_helper.rb:290:in 'respond_to?'
# form_helper.rb:290:in 'apply_form_for_options!'
# form_helper.rb:277:in 'form_for'
<% form_for([@website, @domain]) do | form | %>
<%= form.text_field :name %>
# ArgumentError: wrong number of arguments (1 for 0)
# form_helper.rb:290:in 'respond_to?'
# form_helper.rb:290:in 'apply_form_for_options!'
# form_helper.rb:277:in 'form_for'
<% form_for(:domain, @domain, :url => website_domains_path(@website)) do | form | %>
<%= form.text_field :name %>
# ArgumentError: wrong number of arguments (1 for 0)
# wrapper.rb:14:in 'respond_to?'
# wrapper.rb:14:in 'wrap'
# active_record_helper.rb:174:in 'error_messages_for'
<% form_for(:domain, [@website, @domain]) do | form | %>
<%= form.text_field :name %>
# UndefinedMethodError 'name' for #<Array:0x40fa498>
I have confirmed both @website
and @domain
contain instances of the correct class.
The routes also generate correctly is used like this for example, so I dont think their is an issue with the route or url helpers.
<%= website_domains_path(1) %>
<%= website_data_source_path(1, 1) %>
Rails 2.3.5
© Stack Overflow or respective owner