Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

routing - Rails 3 returning a HTTP 406 Not Acceptable?

I have the following controller code:

  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

and the following routes:

           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"}

Now, aside from the slightly whacky naming - the redirects always result in a 406 Not acceptable. What could be wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...