ngollan-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Dec-28 15:52 UTC
Nested resources form_for problem
Hi, I have a resource map like this: map.resources :users do |user| user.resource :sreg10record end So a User is supposed to have (at most) one Sreg10record. The problem is in the views. I tried following this tutorial: http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial which proposes something like: <% form_for( [@user, @sreg10record] ) do |f| %> However, doing that yields "undefined method `has_key?'' for #<Sreg10record:0xb6f47bc4>". So I tried <% form_for( [:user, @sreg10record] ) do |f| %> as intended for namespaced resources, however that causes the ID of the record to be used in the URL, which then causes the controller to fail when retrieving @user. Experiments with url_for (which appears to be used by form_for anyway) or user_sreg10record_url(@user) failed in more or less entertaining ways too. So, how do I make form_for generate a valid path like "/users/<user_id>/sreg10record"? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ngollan-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Dec-28 16:02 UTC
Re: Nested resources form_for problem
A small addition: when using <% form_for( user_sreg10record_url(@user) ) %> the generated URL is apparently right, but all form fields are left empty. Submitting the form ends up somewhere where "Only get requests are allowed." In the form, there''s a happy mixture of the user''s ID and the record''s ID. On Dec 28, 4:52 pm, "ngol...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org" <ngol...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi, > > I have a resource map like this: > > map.resources :users do |user| > user.resource :sreg10record > end > > So a User is supposed to have (at most) one Sreg10record. The problem > is in the views. I tried following this tutorial:http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-fir... > which proposes something like: > > <% form_for( [@user, @sreg10record] ) do |f| %> > > However, doing that yields "undefined method `has_key?'' for > #<Sreg10record:0xb6f47bc4>". So I tried > > <% form_for( [:user, @sreg10record] ) do |f| %> > > as intended for namespaced resources, however that causes the ID of > the record to be used in the URL, which then causes the controller to > fail when retrieving @user. Experiments with url_for (which appears to > be used by form_for anyway) or user_sreg10record_url(@user) failed in > more or less entertaining ways too. So, how do I make form_for > generate a valid path like "/users/<user_id>/sreg10record"?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---