Form causing error => "Only post requests are allowed"?

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| -%>

Address
<%= f.text_area :address %>

<%= f.submit "Save" %>

<% end -%>

html of generated form

Address
123 some street, boston, ma

<% 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| -%>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs