1
パスワード確認を設定しようとしているのは、ユーザーがパスワードを変更したページだけです。 私のモデルは、このようになります:Authlogic - アップデートのためだけにpassword_confirmationを設定するには?
class User < ActiveRecord::Base
attr_accessor :password_confirmation
acts_as_authentic do |c|
c.validate_login_field = false
c.validate_password_field = false
c.require_password_confirmation = true
c.logged_in_timeout(15.minutes)
end
validates :name, :presence => {:message => 'cannot be blank.'}, :allow_blank => true, :length => {:minimum => 3, :maximum => 40}, :on => :create
validates :email, :presence => {:message => 'address cannot be blank.'}, :allow_blank => true, :format => {:with => /\A[A-Za-z0-9._%+-][email protected][A-Za-z0-9.-]+\.[A-Za-z]+\z/, :message => 'address is not valid. Please, fix it.'}, :uniqueness => true
validates :password, :presence => {:message => 'cannot be blank.'}, :allow_blank => true, :length => { :minimum => 6, :maximum => 40}, :on => :create
validates :password_confirmation, :presence => {:message => 'cannot be blank.'}, :allow_blank => true, :length => { :minimum => 6, :maximum => 40 }, :on => :update
end
と新しいパスワードを保存する私の方法:
def change_password
@user = current_user
if @user.valid_password?(params[:user][:old_password])
if @user.update_attributes(params[:user].reject{|key, value| key == "old_password"})
flash[:notice] = 'Your password was successfuly changed.'
redirect_to :back
else
flash[:warning] = 'You did not fill twice your new password correctly. Please, fix it.'
redirect_to :back
end
else
flash[:warning] = 'Your old password is WRONG! What is your malfunction!?!'
redirect_to :back
end
end
私の問題は、私は、フォーム古いパスワード、新しいパスワード(例を設定している場合ということ、である。新しいパスワードの確認(例: new_password1)、新しいパスワードは&がデータベースに保存されるように変更されますが、これは新しいパスワードのであるためです()。と新しいパスワードの確認は同じではありません...
どのように私は検証ルールを設定する必要がありますか、どこで問題がありますか?アドバイス