0
votes

I am currently using Postman to make a POST request to the following route: 'localhost:3000/members/login'. The content of the post request is as follows:

{ 
  "email": "[email protected]",
  "password": "password"
}

The route is defined as follows:

def login
  puts params.inspect
  puts member_params.to_s
  member = Member.find_by(email: params[:email].to_s.downcase)
end
...
def member_params
  params.require(:member).permit(:email, :password, :password_confirmation)
end

and the output that I receive at the console is as follows:

Started POST "/members/login" for 127.0.0.1 at 2018-01-02 18:56:28 -0800
(2.5ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by MembersController#login as */*
<ActionController::Parameters {"controller"=>"members", "action"=>"login"} permitted: false>
Completed 400 Bad Request in 1ms (ActiveRecord: 0.0ms)



ActionController::ParameterMissing (param is missing or the value is empty: member):

app/controllers/members_controller.rb:94:in `member_params'
app/controllers/members_controller.rb:65:in `login'

As you may have guessed, I am rather new to this. What I am specifically looking for is the following:

1) Is there a quick fix as to why the parameters (email and password) are not being passed into the API from the Postman POST request to help me get this working and

2) To make the answer more generally helpful to future people who might google this question, is there a quick checklist of recommended steps to take when an API call (specifically POST request) does not pass in parameters as intended?

2
I don't know about postman, it would be best if you showed how exactly your http request looked like. - Marek Lipka
Try changing params.require(:member).permit to params.permit as you are not sending the params nested in member key. - Jagdeep Singh

2 Answers

0
votes

Your member_params function requires that a member is passed to it, which is not included in the params you're sending from Postman.

You're not seeing anything being printed because the member_params function is a before_action, which means it happens before your login function is called.

Change your content in Postman to include it.

{ 
    "member":
        {
            "email": "email address",
            "password": "password"
        }
}
-2
votes

I think your json should look like {member:{emai:___, password:_____}}