Rails 3 returning a HTTP 406 Not Acceptable?

后端 未结 3 686
北荒
北荒 2020-12-13 12:29

I have the following controller code:

  def create
    @admin = Admin.new(params[:admin])
    respond_to do |format|
      if @admin.save
        redirect_to         


        
相关标签:
3条回答
  • 2020-12-13 13:17

    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.

    0 讨论(0)
  • 2020-12-13 13:19

    I had a similar error, my controller was only responding to JSON. I needed it to respond to HTML also for the tests to work (which only makes sense):

    class AdsController < ApplicationController
      respond_to :json, :html
    

    I received the error when trying to do: assert_redirected_to ad_url(ad)

    0 讨论(0)
  • 2020-12-13 13:24

    I started having this issue after a deploy in production, even tough everything was working fine in development.

    After some 15 minutes of wasted time, I finally found out that I had forgotten to commit some of the view files (like index.html.erb).

    Using tail -f log/production.log on the server revealed: FATAL -- : ActionController::UnknownFormat (SomeController#index is missing a template for this request format and variant.

    In development the error didn't happen because, obviously, the view file was present.

    0 讨论(0)
提交回复
热议问题