Format.js and json rendering in Rails?

I need to pass a json object and format.js from a Rails controller. if i do

    respond_to do |format|
     format.js 
    end

I am running a javascript file (controllername.js). If i do

    respond_to do |format|
     format.js {render json: @thing} 
    end

I get json ..

Is there a way to get both?

+3
source share
1 answer
respond_to do |format|
  format.json { render json: @thing }
  format.js
end

he will respond as depending on the request.

+3
source

All Articles