Tuesday, 10 September 2013

Posting to Ruby on Rails JSON PUT

Posting to Ruby on Rails JSON PUT

I am trying to post to the following method /users.json
Here's my code in Ruby on Rails
# POST /users
# POST /users.json
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 action: 'show', status: :created, location:
@user }
else
format.html { render action: 'new' }
format.json { render json: @user.errors, status:
:unprocessable_entity }
end
end
end
and inside my user params
def user_params
params.require(:user).permit(:name, :password, :password_confirmation,
:avatar)
end
I am using chrome Advanced REST client to post
(http://postimg.org/image/fphun12fx/)

Rails kept giving me error stating param not found :user, how do I create
the param for user?
Also, if we have the parameter :user, does it mean for jQuery ajax, I
would have to do something like the below?
data: { user: {name: xx, password: xx, password_confirmation: xx} }

No comments:

Post a Comment