在Devise中更改密码

时间:2012-01-24 00:49:53

标签: ruby-on-rails ruby-on-rails-3 devise

编辑:我需要的是/ settings / password中的渲染/设计/注册/编辑

要做到这一点,请将您的观点视为例如/ settings / password

<%= render :template => 'devise/registrations/edit' %>

和这在SettingsHelper

def resource_name
  :user
end

def resource
  @resource = current_user || User.new
end

def devise_mapping
  @devise_mapping ||= Devise.mappings[:user]
end

def devise_error_messages!
  return "" if resource.errors.empty?

  messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
  sentence = I18n.t("errors.messages.not_saved",
                    :count => resource.errors.count,
                    :resource => resource_name)

  html = <<-HTML
          <div id='error'>
            <h2>{sentence}<h2>
            <p>#{messages}</p>

        </div>
  HTML

  html.html_safe
end

1 个答案:

答案 0 :(得分:2)

您可以执行以下操作:

 #routes.rb
 get 'settings/password' => 'users#password'

然后在您的控制器中,创建操作密码:

#users_controller.rb
def password
  redirect_to :edit
end

如果您使用的是Rails 3,则只需执行此操作:

 #routes.rb
 get 'settings/password' => redirect('users/edit')

也许这就是你追求的目标?

 #routes.rb
 devise_for :users do
   get 'settings/password' => 'devise/registrations#edit'
 end