ruby-on-railshttp-status-code-406

Rails 406 for .js.erb


I know this has been asked a lot, but I've looked at all the simple solutions and they're not working.

Firstly, .js.erb responses are working for all my other controllers...I generated a new controller and it won't respond to .js.erb

  def report
    @report = Report.all
    respond_to do |format|
      format.js do
        render :content_type => 'text/javascript'
      end
    end
  end

This route does work and will render html. I have no idea why .js.erb would work for my other controllers and not for a new one. I've done plenty of fiddling before making this new one...so debugging will be hard for me.


Solution

  • Remove the entire respond_to block. Rails will pick the correct view:

    def report
      @report = Report.all
    end