0

I am limiting to 1, so I thought it would simple return an object in this case the same as .find_by_email

Code:

  # GET /users/:identified/type/:social_type
  # Returns a single record - so limit 1
  def find
    @user = User.where("identified = ? AND social_type = ?", params[:identified], params[:social_type]).limit(1)

    if not @user.empty?
      render json: @user.as_json, status: :created
    else
      render json: @user, status: :not_found
    end
  end

Current Response:

[{"id":7,"voy_num":null,"voy_pin":null}]

How can ensure I return a single JSON object?

1
  • .first with 'where' clause query will do the trick. @user = User.where("identified = ? AND social_type = ?", params[:identified], params[:social_type]).first Commented May 19, 2015 at 9:42

1 Answer 1

1

To get the single object, use first with where like this:

@user = User.where("identified = ? AND social_type = ?", params[:identified], params[:social_type]).first
Sign up to request clarification or add additional context in comments.

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.