我正在尝试编写 API 方法供用户注册 spree 应用程序。它在我的本地机器上正常工作,但在服务器上却不行。这是我的 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 and return
end
@user = Spree::User.new(user_params)
if !@user.save
unauthorized
return
end
@user.generate_spree_api_key!
end
并且 sign_up.v1.rabl 是
object @user
attributes :id, :spree_api_key, :email, :firstname, :lastname, :mobile
child(:bill_address => :bill_address) do
extends "spree/api/addresses/show"
end
child(:ship_address => :ship_address) do
extends "spree/api/addresses/show"
end
当我使用以下请求卷曲服务器时
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
它给了我下面的错误是从网络服务器日志中提取的
Started POST "/api/users/sign_up" for 127.0.0.1 at 2015-10-15 11:23:36 +0530
ActiveRecord::SchemaMigration Load (0.3ms) SELECT `schema_migrations`.* FROM `schema_migrations`
Error occurred while parsing request parameters.
Contents:
{user:{email:ml5698@gmail.com,password:12345678,
JSON::ParserError - 795: unexpected token at '{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'
我正在使用 Ruby 2.2 , rails 4, json 1.8.3 ,可能是什么问题,请帮我解决。