Ruby on rails使用rest API调用和Devise进行用户注册
任何人都可以指导我如何在ruby on rails上从移动设备(rest API)注册用户。 我正在使用Devise with Rails 3.0。
它给了我以下错误
Devise中的NameError :: CustomRegistrationsController #create
我用以下方法覆盖了设计注册控制器的function。
def create respond_to do |format| format.html { super } format.json { build_resource if resource.save render :status => 200, :json => resource else render :json => resource.errors, :status => :unprocessable_entity end } end end
这解决了问题,我补充说
skip_before_filter :verify_authenticity_token, :only => :create
避免真实性检查。
制作移动视图比在Android / iOS上制作应用程序更容易吗? 如果你需要API,那么请在/ users / sign_up(和类似的)中使用POST请求,例如,浏览localhost:3000 / users / sign_up并将表单的action参数更改为action="/users.json"
,然后单击submit和您将收到API的回复(在vanilla设置上):
{"email":["has already been taken"],"password":["doesn't match confirmation","is too short (minimum is 6 characters)"]}
这样您就可以使用浏览器调试API(遵循标准约定)。 请注意,只有:format
rails参数在rails路由上更改(您可以选择.json
或.xml
进行API响应)
我的浏览器发送的POST信息:
"utf8=✓&authenticity_token=n5vXMnlzrXefnKQEV4SmVM8cFdHDCUxMYWEBMHp9fDw%3D&user[email]=asd%40fasd.org&user[password]=321&user[password_confirmation]=1233&commit=Sign+up"