[英]ActionController::MethodNotAllowed (Only get, put, and delete requests are allowed.)
[英]ActionController::MethodNotAllowed (Only get and post requests are allowed.):
不知道發生了什么。 我使用下面的代碼來嘗試編輯類別的名稱,但是我收到了上面的錯誤消息。 我用於表單並提交以進行編輯的代碼是:-
<% form_for :category, :url => categories_url(@category),:html => { :method => :put } do |f| -%>
<p>Name: <br /><%= f.text_field :name, :size => 60 %></p>
<%= submit_tag 'Save' %> or <%= link_to 'cancel', admin_categories_url%>
非常簡單的東西。 我的控制器代碼是:-def edit @category = Category.find(params [:id])結束
#PUT / categories / 1#PUT /categories/1.xml def update @category = Category.find(params [:id])@ category.update_attributes(params [:category])
respond_to do |wants|
wants.html { redirect_to admin_categories_url }
wants.xml { render :xml => @category.to_xm }
end
結束
該代碼還可以用於其他方面(例如博客文章),所以我不確定我哪里出錯了。
我認為您想要:url => category_url(@category)
(非復數)。
這通常會更干凈一些。讓路由系統找出如何最好地保存@category。
/app/controllers/admin_categories_controller.rb ( 據此猜測)
def new
@category = Category.new
end
/app/views/admin_categories/new.html.erb
<% form_for @category do |f| %>
<p>
<%= f.label :name%>: <%= f.text_field :name, :size=>60%>
</p>
<%= f.submit :save%> or <%= link_to 'cancel', admin_categories_url%>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.