无法更改用户密码(设计宝石)

时间:2012-09-04 11:06:37

标签: ruby-on-rails devise

我有这个问题 - 我需要创建一个页面,用户可以通过提供他当前的密码来更改他的密码。对于这个页面,我需要,对于其他 - 没有。

我遵循了这个https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-password - 我想使用解决方案#3

我创建了新的控制器并添加了适当的东西。

这是我的控制器:

class EditUserController < ApplicationController
  before_filter :authenticate_user!


def edit_password
 @user = current_user
end

def update_password
 @user = User.find(current_user.id)
 if @user.update_with_password(params[:user])
  # Sign in the user by passing validation in case his password changed
  #sign_in @user, :bypass => true//commented this, because when I'm entering current_password
  #redirect_to root_path         //it just redirects me to root_path
  redirect_to root_path
 else
   render "edit_password"
 end
end

end

注册控制器

def update
 self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)

 params[:user].delete(:password) if params[:user][:password].blank?
 params[:user].delete(:password_confirmation) if params[:user][:password_confirmation].blank?

 if resource.update_attributes(params[resource_name]) 
  set_flash_message :notice, :updated if is_navigational_format?
  sign_in resource_name, resource, :bypass => true
  respond_with resource, :location => after_update_path_for(resource)
 else
  clean_up_passwords(resource)
  redirect_to :back
 end

端 和我的代码来自edit_password.html.erb

 <%= form_for(@user, :url => { :action => "update_password" }, :method => :put) do |f| %>   
   <%= devise_error_messages! %>
  ...other fields...
  <% end %>

和路线:

     match "/edit_password", to: 'edit_user#edit_password'
     put "edit_user/update_password"

但是当我提交表格时 - 没有任何改变。没有错误,只是将我重定向到

      edit_user/update_password

我怎么解决这个问题?我做错了什么?

0 个答案:

没有答案
相关问题