Hi there, I''ve been trying to fix this for the whole afternoon, but don''t get it to work: I have: -> Nested RESTful resources/routes like this: map.resources :users, :member => { :enable => :put, :view => :get } do |users| users.resource :account users.resources :roles users.resources :messages end -> A link on a page (should bring up a form for a new message "new.html.erb"): <%= link_to ''Send a message'', new_user_message_path(@user, :target_id => @member.id) %> -> The "MessagesController" like this: def new @target = User.find(params[:target_id]) @message = Message.new end -> And the message form "new.html.erb" like this: <% form_for @message do |f| %> <p> <label for=''subject''>Subject:</label> <%= f.text_field :subject, :focus => true %> </p> [...etc...] <% end %> ...but I get the error: NoMethodError in Messages#new Showing messages/new.html.erb where line #4 raised: undefined method `messages_path'' for #<ActionView::Base:0x554b884> Line 4 is: <% form_for @message do |f| %> As far as I know, with RESTful routes, it''s sufficient to only have the "@message" in the form header. Rails 2.0 should automatically understand that "@message" is a *new* message and therefor redirect me to the "new" form, right? Thank you very much for any hint which could help me get out of the mess! Tom -- 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 -~----------~----~----~----~------~----~------~--~---
Jan Foeh
2008-Apr-22 21:20 UTC
Re: RESTful routes: How to code the "create" form correctly
> NoMethodError in Messages#new > Showing messages/new.html.erb where line #4 raised: > undefined method `messages_path'' for #<ActionView::Base:0x554b884> > > Line 4 is: <% form_for @message do |f| %>Correct me if I''m wrong, but as far as I know the form_for helper is not able to deal with nested resources when used in the super compact fashion above. You''re right, Rails knows that it is dealing with a new object; however it tries to use message_path instead of user_messages_path(@user) to create the url. This format should work: <% form_for :messages, @message, :url => user_messages_path(@user) do |f| %> Cheers, Jan -- 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 -~----------~----~----~----~------~----~------~--~---
Jan Foeh
2008-Apr-22 21:22 UTC
Re: RESTful routes: How to code the "create" form correctly
.. that should have read "messages_path instead of user_messages_path" -- 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 -~----------~----~----~----~------~----~------~--~---
Hendrik Mans
2008-Apr-23 00:04 UTC
Re: RESTful routes: How to code the "create" form correctly
On Apr 22, 10:20 pm, Jan Foeh <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> <% form_for :messages, @message, > :url => user_messages_path(@user) do |f| %>form_for [@user, @message] do - Hendrik --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jan Foeh
2008-Apr-23 07:05 UTC
Re: RESTful routes: How to code the "create" form correctly
Hendrik Mans wrote:> On Apr 22, 10:20�pm, Jan Foeh <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> � <% form_for :messages, @message, >> � � � � � � � :url => user_messages_path(@user) do |f| %> > > form_for [@user, @message] doNice! Thanks Hendrik. -- 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 -~----------~----~----~----~------~----~------~--~---
Very cool, thanks a lot guys! -- 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 -~----------~----~----~----~------~----~------~--~---