gpt4 book ai didi

ruby-on-rails - Rails 3 返回 HTTP 406 Not Acceptable ?

转载 作者:行者123 更新时间:2023-12-03 06:21:39 25 4
gpt4 key购买 nike

我有以下 Controller 代码:

  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 Not Acceptable 。可能出了什么问题?

最佳答案

删除 respond_to do |format| block 。因为您没有指定您要响应的格式,例如format.html { #您的代码在这里} 。检查 respond_to 的文档如何正确使用。

关于ruby-on-rails - Rails 3 返回 HTTP 406 Not Acceptable ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3751030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com