Hi, I''m following a tutorial which creates a rails project using the scaffolding generator (in Rails 2.3.8). One of the exercises at the end of this tutorial is to put the form used in the scaffolding''s "new" and "update" views into a partial. So, I created a file "_form.html.erb" in the views folder of my app. In "new.html.erb" I call the partial thus: <%= render :partial => "form", :locals => {:url => {:action => "create"} %> This works as it should and I have no problems creating a new dataset. In "edit.html.erb" I wrote this: <%= render :partial => "form", :locals => {:url => {:action => "update", :id => @flight.id}} %> but when I try to update an existing record I get the error: Unknown action No action responded to 11. Actions: create, destroy, edit, index, new, show, and update (where 11 is the id or the object I am trying to update) Using Firebug to check where the form is being sent, I see: <form method="post" action="/flights/11"> When I run "rake routes" I see: PUT /flights/:id(.:format) {:controller=>"flights", :action=>"update"} What am I missing? Can anyone point me in the right direction? Thanks very much in advance. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 13, 10:45 am, Jim Burgess <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> When I run "rake routes" I see: > PUT /flights/:id(.:format) {:controller=>"flights", :action=>"update"} > > What am I missing? > Can anyone point me in the right direction? > Thanks very much in advance. >because a route isn''t just a path, it''s also an HTTP method. In the case of update the method is PUT (browsers don''t let forms use methods other than POST or GET but rails lets you simulate the extra methods by adding a form parameter). You may be overcomplicating things - if you do form_for @flight ... rails will pick the right path & method for you ( based on whether the record is a new record or not) Fred> -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Cheers for the explanation, Fred. Following your advice I passed the appropriate HTTP method to the form in the partial and now everything works as it should. In case it helps anyone else, I now have: new.html.erb: <%= render :partial => "form", :locals => {:url => {:action => "create"}, :method => :post} %> edit.html.erb: <%= render :partial => "form", :locals => {:url => {:action => "update", :id => @flight}, :method => :put} %> _form.html.erb: <% form_for :flight, :url => url, :html=>{:method=> method} do |f| %> Thanks again. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jim Burgess wrote in post #968051:> Cheers for the explanation, Fred. > Following your advice I passed the appropriate HTTP method to the form > in the partial and now everything works as it should. > > In case it helps anyone else, I now have: > > new.html.erb: > <%= render :partial => "form", :locals => {:url => {:action => > "create"}, :method => :post} %> > > edit.html.erb: > <%= render :partial => "form", :locals => {:url => {:action => "update", > :id => @flight}, :method => :put} %> > > _form.html.erb: > <% form_for :flight, :url => url, :html=>{:method=> method} do |f| %>But you missed Fred''s point entirely: you don''t need to do that! Rails will test @flight.new_record? and pick the method accordingly. So all you need in both new.html.erb and edit.html.erb is render :partial => ''form'' and in _form.html.erb, just form_for @flight You''re reinventing what Rails already does for you.> > Thanks again.Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> But you missed Fred''s point entirelyOops, it appears I did.> So all you need in both new.html.erb and edit.html.erb is > render :partial => ''form'' > and in _form.html.erb, just > form_for @flightYup, that works embarrassingly well! Thanks a lot for pointing that out. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.