1

この問題があります - ユーザーが現在のパスワードを入力してパスワードを変更できるページを作成する必要があります。

私はこれに従った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

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

どうすればこれを解決できますか? 私が間違っていることは何ですか?

4

0 に答える 0