3

I currently have the following code and it works fine:

respond_to do |format|
  format.json { render :show, status: :ok }
end

I believe :show is referring to a jbuilder view.

However, if I wanted to add a local variable to the json render, how would I do that?

I've tried the following but it hasn't worked.

auth = true
format.json { render :show, :include => auth, status: :ok }

and I've also tried

auth = true
format.json { render :show.include(auth), status: ok }

From what I found at render :json does not accept options

Community
  • 1
  • 1
Arian Faurtosh
  • 17,987
  • 21
  • 77
  • 115

1 Answers1

4

try this one

format.json { render :show, locals:{auth: auth}, status: :ok }

now you have a variable auth in your show view

rob
  • 2,136
  • 8
  • 29
  • 37