Mr McDonald
Mr McDonald

Reputation: 483

Multiple response with render :json

If I want to render 2 or more elements in my controller with respond json: what do I have to do? I tried:

render json: @user.errors.full_messages

//another element to render

render json: other element...

This doesn't work.

Upvotes: 0

Views: 289

Answers (1)

eugenioy
eugenioy

Reputation: 12393

You need to call render json: just one time.

One way to work around this is to build a single JSON that would contain both objects you want to return.

render json: {:errors => @user.errors.full_messages, 
              :other_element => other_element }

Upvotes: 3

Related Questions