简体   繁体   中英

Change password in Devise

EDIT: All I need is render /devise/registrations/edit in /settings/password

To do that put this your view eg /settings/password

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

and This in 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

You can do the following:

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

And then in your controller, create the action password:

#users_controller.rb
def password
  redirect_to :edit
end

If you are using Rails 3, you can simply do this:

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

Maybe this is what you are after?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM