質問

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.

役に立ちましたか?

解決

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

def report
  @report = Report.all
end

他のヒント

If you are getting a 406

You need to explicitly disable erb's layout template checking.

render layout: false

You can keep respond_to and format if you need them for supporting other formats.

(NOTE: dynamic js for Content Security Policy purposes?)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top