Rails 3返回不可接受的HTTP 406? [英] Rails 3 returning a HTTP 406 Not Acceptable?
本文介绍了Rails 3返回不可接受的HTTP 406?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下控制器代码:
def create
@admin = Admin.new(params[:admin])
respond_to do |format|
if @admin.save
redirect_to(@admin, :notice => 'Admin was successfully created.')
else
render :action => "new"
end
end
end
def update
@admin = Admin.find(params[:id])
respond_to do |format|
if @admin.update_attributes(params[:admin])
redirect_to(admin_admins_path, :notice => 'Admin was successfully updated.')
else
render :action => "edit"
end
end
end
路线:
admin_admins GET /admin/admins(.:format) {:action=>"index", :controller=>"admin/admins"}
admin_admins POST /admin/admins(.:format) {:action=>"create", :controller=>"admin/admins"}
new_admin_admin GET /admin/admins/new(.:format) {:action=>"new", :controller=>"admin/admins"}
edit_admin_admin GET /admin/admins/:id/edit(.:format) {:action=>"edit", :controller=>"admin/admins"}
admin_admin GET /admin/admins/:id(.:format) {:action=>"show", :controller=>"admin/admins"}
admin_admin PUT /admin/admins/:id(.:format) {:action=>"update", :controller=>"admin/admins"}
admin_admin DELETE /admin/admins/:id(.:format) {:action=>"destroy", :controller=>"admin/admins"}
现在,除了名称有些古怪之外,重定向始终导致406不可接受。
Now, aside from the slightly whacky naming - the redirects always result in a 406 Not acceptable. What could be wrong?
推荐答案
删除 respond_来执行| format |
块。由于您未指定要回复的格式,例如 format.html {#您的代码在这里}
。
检查 respond_to 的文档,以正确使用它。
Remove respond_to do |format|
blocks. Because you are not specifying to what format are you responding, e.g. format.html { #your code here }
.
Check documentation of respond_to how to use it properly.
这篇关于Rails 3返回不可接受的HTTP 406?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文