0

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?

2 Answers 2

7

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

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

Comments

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

Comments

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.