0

I am in the process of learning ruby on rails, I have a controller named welcome_controller and the controller has a json object, and I have a view named index.html.haml
How do I access that json object from the view

render 'index', :layout => false

3 Answers 3

0

Try this

render json: @payment.to_json

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

Comments

0
var my_var = JSON.parse(('<%= my_controller_json %>') 
console.log(JSON.stringify(my_var))

Put this in of your index page for more info see this question

Comments

0

Try like this,

render json: @your_json_object

3 Comments

this works but I need to render the view also this would give me a double render error
respond_to do |format| format.html # index.html.erb format.json { render json: @your_json_object } end
do I have to rename index.html.haml to index.erb

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.