Hi everyone, I''m using RESTful routes and am trying to implement a simple comment form. For some reason when I submit the form I get an error that it''s trying to render the index action, instead of processing the comment and returning me to the same page. Here''s my form_for: <% form_for @comment do |f| %> <%= f.text_area :body, :class => "small_textarea" %> <button type="submit" class="button positive"> Post your comment </button> <% end %> Here''s what I have in the HTML: <form action="/comments" class="new_comment" id="new_comment" method="post"> Shouldn''t it be: <form action="/comments/create"...>? It doesn''t seem to understand that I want it to create the comment. Even when I do this: <% form_for @comment, :url => {:controller => "comments", :action => "create"} do |f| %> It gives me the exact same URL. What am I missing here? -- 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 Thu, Sep 18, 2008 at 3:51 PM, Dave Amos <rails-mailing-list-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt> wrote:> > Hi everyone, > > I''m using RESTful routes and am trying to implement a simple comment > form. For some reason when I submit the form I get an error that it''s > trying to render the index action, instead of processing the comment and > returning me to the same page. Here''s my form_for: > > <% form_for @comment do |f| %> > <%= f.text_area :body, :class => "small_textarea" %> > <button type="submit" class="button positive"> > Post your comment > </button> > <% end %> > > Here''s what I have in the HTML: > > <form action="/comments" class="new_comment" id="new_comment" > method="post">This is correct. The form_for will use a POST to create a new Comment, and a PUT to update an existing one, and it figures that out for you. Do you have a resources entry for the comments in your routes.rb à la map.resources :comments You can run rake routes in your application directory to see the Restful routes available. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks! I realized that I didn''t restart my server after I edited my routes file. Now it works! -- 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 -~----------~----~----~----~------~----~------~--~---