3

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

    respond_to do |format|
     format.js 
    end

I get the javascript file (controllername.js) to run. If I do

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

I get the json..

Is there a way to get both?

1 Answer 1

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

it will respond both depending on the request.

Sign up to request clarification or add additional context in comments.

1 Comment

yep, failed for me as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.