ActionController::MethodNotAllowed(仅允许 get 和 post 请求。):
不知道发生了什么事。我使用了以下代码来尝试编辑类别的名称,但收到上面的错误消息。我的表单和提交编辑代码是: -
<% 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%>
非常简单的东西。我的控制器代码是:- 默认编辑 @category = Category.find(params[:id]) 结束
# PUT /类别/1 # PUT /categories/1.xml 默认更新 @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
end
这段代码适用于其他事情 - 例如博客文章,所以我不确定我哪里出错了。帮助??
Not sure what's going on. I've used the following bit of code to try and edit the name of a category, but I'm getting the error message above. My code for the form and submit for the edit is: -
<% 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%>
So pretty straight forward stuff. My controller code is: -
def edit
@category = Category.find(params[:id])
end
# 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
end
This code has worked for other things - such as blog articles, so I'm not sure where I{"m going wrong. Help??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你想要
:url => Category_url(@category)
(非复数)。I think you want
:url => category_url(@category)
(non-plural).这往往会更干净一些...让路由系统找出如何最好地保存@category。
/app/controllers/admin_categories_controller.rb(猜测)
/app/views/admin_categories/new.html.erb
This tends to be a bit cleaner... Let the Routing system figure out how best to save the @category.
/app/controllers/admin_categories_controller.rb (guessed at this)
/app/views/admin_categories/new.html.erb