HelloWorld
HelloWorld

Reputation: 7286

Using a custom JSON format for rails 3

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

Answers (2)

ABrukish
ABrukish

Reputation: 1452

if exist_user
    format.json { render :json => {:msg => 'has this user'} }
else

Upvotes: 1

Chamnap
Chamnap

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

Related Questions