ruby on rails - Error occurred while parsing request parameters JSON::ParserError - 795: unexpected token at -
i trying write api methods user sign on spree app. it's working on local machine not on server. here code of user_decorator_controller.rb
def sign_up @user = spree::user.find_by_email(params[:user][:email]) if @user.present? render "spree/api/users/user_exists", :status => 401 , return end @user = spree::user.new(user_params) if !@user.save unauthorized return end @user.generate_spree_api_key! end
and sign_up.v1.rabl
object @user attributes :id, :spree_api_key, :email, :firstname, :lastname, :mobile child(:bill_address => :bill_address) extends "spree/api/addresses/show" end child(:ship_address => :ship_address) extends "spree/api/addresses/show" end
when curl server below request
curl -v -h 'content-type: application/json' -h 'accept: application/json' -x post -d {"user":{"email":"ml5698@gmail.com","password":"12345678", "firstname":"m", "lastname":"l", "mobile":"9999888877"}} http://localhost:3000/api/users/sign_up
it gives me above error below extracts web server log
started post "/api/users/sign_up" 127.0.0.1 @ 2015-10-15 11:23:36 +0530 activerecord::schemamigration load (0.3ms) select `schema_migrations`.* `schema_migrations` error occurred while parsing request parameters. contents: {user:{email:ml5698@gmail.com,password:12345678, json::parsererror - 795: unexpected token @ '{user:{email:ml5698@gmail.com,password:12345678,': json (1.8.3) lib/json/common.rb:155:in `parse' activesupport (4.2.4) lib/active_support/json/decoding.rb:26:in `decode'
i using ruby 2.2 , rails 4, json 1.8.3 , issue, please me resolve it.
your error in use of command line curl. use -d
switch, , pass parameters it. parameters parsed until next space, parameters being passed in are
{user:{email:ml5698@gmail.com,password:12345678,
this you're seeing in error message, , not formed json, parsing error.
try quoting -d
parameters so:
curl -v -h 'content-type: application/json' -h 'accept: application/json' -x post -d '{"user":{"email":"ml5698@gmail.com","password":"12345678","firstname":"m","lastname":"l","mobile":"9999888877"}}' http://localhost:3000/api/users/sign_up
Comments
Post a Comment