Rails 3 返回 HTTP 406 不可接受? [英] Rails 3 returning a HTTP 406 Not Acceptable?

查看:19
本文介绍了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_to do |format| 块.因为您没有指定要响应的格式,例如format.html { #your code here } .查看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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆