Ruby on Rails:只允许获取,放置和删除

时间:2010-11-23 19:38:37

标签: ruby-on-rails

我的观点:

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

部分......没什么特别的

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

我的错误:

ActionController::MethodNotAllowed

Only get, put, and delete requests are allowed.

1 个答案:

答案 0 :(得分:1)

MethodNotAllowed似乎来自基于资源的路由。基于资源的路由需要不同的方法名称来匹配操作。在您的情况下,您应该在:method => :post中提供form_for,类似于:

<% form_for @address, new_address_path, :method => :post) do |f| -%>