Reputation: 7286
In a rails app I have an action that returns a json string. It looks something like this:
if exist_user
format.json { render json: {:msg => 'has this user'}}
else
but rails show error:too few arguments
How do I render custom json string?
Upvotes: 0
Views: 3327
Reputation: 1452
if exist_user
format.json { render :json => {:msg => 'has this user'} }
else
Upvotes: 1
Reputation: 4766
You need to have respond_to
block, otherwise it doesn't know the format to send back.
respond_to do |format|
if exist_user
format.json { render json: {:msg => 'has this user'} }
else
end
end
Check out this for more detail, http://api.rubyonrails.org/classes/ActionController/Responder.html
Upvotes: 7