My view:
<h1>New Address</h1>
<% form_for @address, :url => new_address_path do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :object => f %>
<%= f.submit "Add Address" %>
<% end %>
Partial... nothing special
<%= form.label :number %><br />
<%= form.text_field :number %><br />
<br />
<%= form.label :street %><br />
<%= form.text_field :street %><br />
<br />
<%= form.label :city %><br />
<%= form.text_field :city %><br />
<br />
<%= form.label :state %><br />
<%= form.text_field :state %><br />
<br />
<%= form.label :zip_code %><br />
<%= form.text_field :zip_code %><br />
<br />
<br />
my error:
ActionController::MethodNotAllowed
Only get, put, and delete requests are allowed.
MethodNotAllowed
seems to come from resource-based routing. Resource-based routing requires distinct method names to match actions. In your case, you should supply :method => :post
in form_for
, something like that:
<% form_for @address, new_address_path, :method => :post) do |f| -%>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.