ruby-on-railsrestactiverecordpostman

Param is missing or the value is empty: user


I'm using Postman to test my API and I'm getting this error when making a call to http://localhost:3000/users.json to create a new user:

param is missing or the value is empty: user

All the parameters seem to be ok.

I set this in my application controller:

protect_from_forgery with: :null_session 

My controller method is the basic scaffold generated method:

def create
  @user = User.new(user_params)

  respond_to do |format|
    if @user.save
      format.html { redirect_to @user, notice: 'User was successfully created.' }
      format.json { render :show, status: :created, location: @user }
    else
      format.html { render :new }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

What am I doing wrong?

EDIT:

Here's a screenshot of what I'm doing in Postman.

enter image description here


Solution

  • The issue was that my parameters weren't wrapped up as a user object. For instance, in my case, I would have to change the parameter:

    username
    

    For:

    user[username]
    

    Doing that for all parameters made the test work.