如何在rails 3.2中使用确认密码验证密码
我的代码不起作用
你可以告诉我的错误在哪里
我尝试了许多变化来更改控制器中的代码。
密码保存但未验证到密码确认字段和密码字段。
请帮帮我,帮帮我)))
意见
<%= form_for :password, :url => { :action => "change_password" }, :id => @user do |f| %>
<% if @user.errors.any? %>
<div class="error_messages">
<h2>Form is invalid</h2>
<ul>
<% for message in @user.errors.full_messages %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.password_field :password %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Save", :class => "button blue" %>
<% end %>
用户控制器
def change_password
@page_title = "Changing Zetfon account password"
@user = current_user
if request.post?
@user.password = Digest::SHA1.hexdigest(params[:password][:password])
if @user.save
redirect_to :action => 'profile'
flash[:status] = "Your password was changed. Next time you sign in use your new password."
else
flash[:status] = _('Your password not changed')
render :action => "change_password"
end
end
end
用户模型
validates_confirmation_of :password
attr_accessible :password_confirmation
attr_accessor :password