Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 595
8vius Avatar asked Nov 21 '25 03:11

8vius


1 Answers

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.

like image 172
8vius Avatar answered Nov 22 '25 16:11

8vius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!