Привет, я новичок в рубине, и у меня возникают проблемы при обновлении пароля пользователя. Как я могу подтвердить старый пароль текущим паролем? чтобы изменить его, поле пароля и поле password_confirmation не проверяются! ... Это мой код users_controller: ... Также у меня есть некоторые ошибки в sign_in (current_user,:bypass=>true)
при попытке сохранить вход в систему, когда пароль изменено
def edit
@user=User.find(params[:id])
@title="Editar Informacion"
end
def update
@user=User.find(params[:id])
if @user.update_attributes(params[:user])
sign_in(current_user, :bypass => true)
flash[:success]="Profile updated"
redirect_to edit_user_path(current_user)
else
@title="Edit user"
render 'edit'
end
end
моя модель пользователя:
attr_accessor :password
attr_accessible :name,:email,:lastname,:password,:password_confirmation
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :name,:presence=>true,
:length=>{:maximum=>50}
validates :lastname,:presence=>true,
:length=>{:maximum=>50}
validates :email,:presence=>true,
:format=>{:with => email_regex},
:uniqueness=> {:case_sensitive=>false}
validates :password,:presence=>true,
:confirmation=>true,
:length=>{:within=>6..40},
:on=>:create
before_save :encrypt_password
def has_password?(submitted_password)
encrypted_password == encrypt(submitted_password)
end
def self.authenticate(email, submitted_password)
user = find_by_email(email)
return nil if user.nil?
return user if user.has_password?(submitted_password)
end
И мой вид редактирования:
<%=form_for @user do |c| %>
<%= render 'shared/error_messages', :object => c.object %>
<table>
<tr>
<td class="field">
<%=c.label :old_password,"Contraseña anterior"%><br />
<%=c.password_field :old_password%>
</td>
</tr>
<tr>
<td class="field">
<%=c.label :password, "Contraseña"%><br />
<%=c.password_field :password%>
</td>
<td class="actions" rowspan="3">
<%=c.submit "Guardar Cambios"%>
</td>
</tr>
<tr>
<td class="field">
<%=c.label :password_confirmation,"Confirmar Contraseña"%> <br />
<%=c.password_field :password_confirmation%>
</td>
</tr>
</table>
<%end%>
Спасибо!
Появляется эта ошибка:
NoMethodError in SessionsController#create
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
Полагаю, я не проверяю :old_password
с текущим паролем ...: S