3

Here is my code in controller:

def login
  @user = params[:user]
  render :json => @user
end

And here is my POST data:

{
  "user": {
    "email":"2",
    "password":2
  }
}  

But I can only retrieve a JSON like:

{
  "email": "2",
  "password": 2
}

How can I parse JSON by params for both email and password, and use the parameter like

params[:email]
params[:password]

so that i can compare my params to the database. Thanks a lot!

1 Answer 1

4

According to what I understood, you need to get the data email and password directly from params[]. This is simply a nested params so you can do

params['user']['email']
params['user']['password']
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.