I just started coding in Rails in order to create an API an I've already hit a wall. I'm trying to create a user using a POST request. Here's my users controller which was created using the scaffold command:
def create
@user = User.new(params[:user])
logger.info(@user.to_json)
if @user.save
render json: @user, status: :created, location: @user
else
render json: @user.errors, status: :unprocessable_entity
end
end
The user model only has one validation validates :name, presence: true and that keeps failing because apparently the params is always empty. To test the calls I'm using Postman - REST Client on Chrome and the URL I'm hitting is http://localhost:3000/users . I'm not sure what is it that I'm doing terribly wrong. The same setup with the form and http works fine.
I tried formatting the JSON object in different ways but nothing works. So far I've used:
- {"user":{"name":"test"}}
- {{"name":"test"}}