我构建了一个rails api的javascript前端(ember),并使用devise进行用户身份验证。
所有的工作都很好,但是密码找回给我带来了困难。我查看了devise中的views/devise/password/edit.html.erb
,发现它的属性似乎是password
、new_password
和password_reset_token
。
我从发送电子邮件的url中捕获密码重置令牌,并通过它构造以下ajax调用:
$.ajax({
url: '/users/password.json',
type: 'PUT',
data: {password: this.get('password'), password_confirmation: this.get('passwordconfirmation'), reset_password_token: this.get('content.reset_token')}
});
我可以看到呼叫被接受了,但我得到了一个我不能理解的设计错误。我认为这与从标准视图传回的resource
有关,但我认为我在ajax调用中的/user
部分已经涵盖了这一点。
我在网上能找到的所有东西都是关于登录和更改密码的,没有关于这一点的。
我得到的错误是:
Started PUT "/users/password.json" for 127.0.0.1 at 2013-05-29 09:01:36 +0200
Processing by Devise::PasswordsController#update as JSON
Parameters: {"password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "reset_password_token"=>"[FILTERED]"}
Completed 500 Internal Server Error in 1ms
NoMethodError - undefined method `[]' for nil:NilClass:
(gem) devise-2.1.2/lib/devise/models/recoverable.rb:125:in `reset_password_by_token'
(gem) devise-2.1.2/app/controllers/devise/passwords_controller.rb:30:in `update'
耽误您时间,实在对不起。
发布于 2013-05-30 03:00:19
解决方案是将属性包装在资源中(在我的示例中为user):
$.ajax({
url: '/users/password.json',
type: 'PUT',
data: {'user[password]': this.get('password'), 'user[password_confirmation]': this.get('passwordconfirmation'), 'user[reset_password_token]': this.get('content.reset_token')}
});
发布于 2015-10-12 14:23:39
我的方式:
$.ajax({url: '/users/password', type: 'PUT', data: { password: $password, password_confirmation: $password_confirmation, current_password: $current_password }});
如果你没有解决它,你可以试一下......
https://stackoverflow.com/questions/16807937
复制相似问题