Why does the form give the error "Only post requests are allowed." when submitted to my action? I know the form is supposed to be a post. the rake routes looks ok. some reason there is a "_method"=>"put" in the reques parameters, would this cause it? how do i change the form code to prevent this? ## Request ## Parameters: {"commit"=>"Save", "_method"=>"put", "authenticity_token"=>"291f0f51779490f481edec3fef506b14a2797263", "address"=>{"address"=>"123 some street, boston, ma"}} ## rake routes verify_edit_club_address POST /clubs/:club_id/addresses/:id/verify_edit {:controller=>"addresses", :action=>"verify_edit"} ## form.html.erb <% form_for([@club, @address], :url => verify_edit_club_address_path(@club, @address)) do |f| -%> <p> <b>Address</b><br /> <%= f.text_area :address %> </p> <p> <%= f.submit "Save" %> </p> <% end -%> ## html of generated form <form action="/clubs/1/addresses/6/verify_edit" class="edit_address" id="edit_address_6" method="post"> <div style="margin:0;padding:0"> <input name="_method" type="hidden" value="put"> <input name="authenticity_token" type="hidden" value="291f0f517..."> </div> <p> <b>Address</b><br> <textarea cols="40" id="address_address" name="address[address]" rows="20"> 123 some street, boston, ma </textarea> </p> <p> <input id="address_submit" name="commit" type="submit" value="Save"> </p> </form> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Müller
2008-Jul-14 09:09 UTC
Re: form causing error => "Only post requests are allowed"???
> <% form_for([@club, @address], :url => > verify_edit_club_address_path(@club, @address)) do |f| -%>This way, Rails should be able to find out the right method by itself. It depends on the state of @address. If it''s generated with @address = Adress.new() and not saved, it''ll generate a put, otherwise if it''s based on an record in the db, (eg Address.find(...)) it''ll be a post But you can change the form method easy enough if necessary: <% form_for([@club, @address], :url => verify_edit_club_address_path(@club, @address), :method => :post) 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---