Hello everybody, Here you can see my short code: # in routes.rb: map.resources :users # in users_controller.rb def new @user = User.new end # in views/users/new.html.erb: <% form_for @user do |f| %> And that work very well. I would like to update the current route like this: # in routes.rb: map.resources :apps do |app| app.resources :users end # in users_controller.rb def new @user = User.new @user.app_id = the_current_app.id end But after refresh, I got this error: NoMethodError in Users#new Showing users/new.html.erb where line #1 raised: undefined method `users_path'' for #<ActionView::Base:0x20c4a34> Extracted source (around line #1): 1: <% form_for @user do |f| %> Is there a clean way to solve this error? (I believe it''s possible to add a :url parameter in the form_for tag but I don''t know if it''s the best way.) Thanks a lot -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sep 30, 6:47 pm, Panda Beer <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello everybody, > > Here you can see my short code: > > # in routes.rb: > map.resources :users > > # in users_controller.rb > def new > @user = User.new > end > > # in views/users/new.html.erb: > <% form_for @user do |f| %> > > And that work very well. I would like to update the current route like > this: > > # in routes.rb: > map.resources :apps do |app| > app.resources :users > end > > # in users_controller.rb > def new > @user = User.new > @user.app_id = the_current_app.id > end > > But after refresh, I got this error: > > NoMethodError in Users#new > > Showing users/new.html.erb where line #1 raised: > > undefined method `users_path'' for #<ActionView::Base:0x20c4a34> > Extracted source (around line #1): > > 1: <% form_for @user do |f| %> > > Is there a clean way to solve this error? (I believe it''s possible to > add a :url parameter in the form_for tag but I don''t know if it''s the > best way.) > > Thanks a lot > -- > Posted viahttp://www.ruby-forum.com/.Try: <% form_for @app, @user do |f| %> Where your controller should look like def new @app = App.find(params[:app_id]) @user = User.new @user.app_id = params[:app_id] end --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 30, 8:36 pm, Erol Fornoles <erol.forno...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> <% form_for @app, @user do |f| %>Sorry, it should be: <% form_for [@app, @user] do |f| %> --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Erol Fornoles wrote:> On Sep 30, 8:36�pm, Erol Fornoles <erol.forno...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > <% form_for [@app, @user] do |f| %>Many thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---