maki
maki

Reputation: 535

devise cannot change password

I have the standard devise approach to change the user's password in my code:

<%= link_to "Change your password", edit_user_password_path, :class => "" %>

but then I click on the link I got redirected to main page with message that user is already signed in, the output in console is:

Started GET "/users/password/edit" for 127.0.0.1 at 2015-06-11 16:11:04 +0300
Processing by Devise::PasswordsController#edit as HTML
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 4 LIMIT 1
  Role Load (0.2ms)  SELECT "roles".* FROM "roles" INNER JOIN "roles_users" ON "roles"."id" = "roles_users"."role_id" WHERE "roles_users"."user_id" = 4 AND "roles"."name" = 'admin' LIMIT 1
Redirected to http://localhost:3000/admin
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 4ms (ActiveRecord: 0.3ms)

In my routes I have:

devise_for :users, :controllers => { :registrations => "registrations", sessions: "sessions" }
resources :users,    :only => [:show]

registartions controller:

class RegistrationsController < Devise::RegistrationsController

  def new
    build_resource({:unconfirmed_company_id => params[:unconfirmed_company_id], :email => params[:email], :company_id => params[:company_id]})
    respond_with self.resource
  end

  def build_resource(hash=nil)
    super
    if hash
      self.resource.company_id = hash[:company_id]
      self.resource.unconfirmed_company_id = hash[:unconfirmed_company_id]
      self.resource.email = hash[:email]
    end
    self.resource
  end


end

Upvotes: 1

Views: 686

Answers (2)

thegauraw
thegauraw

Reputation: 5728

Its because this edit_user_password feature of devise is used for password recovery instead.

To change the password of logged-in users, go with registerable module.

Upvotes: 2

shilpa
shilpa

Reputation: 21

Try this one ..

In routes.rb

 devise_for :users, :controllers => { :registrations => "registrations", :sessions => "sessions", :passwords => "passwords",  :confirmations => "confirmations"}

If you use the latest Devise with Strong Parameters, you should add this line to your ApplicationController.rb

class ApplicationController < ActionController::Base
 before_filter :configure_permitted_parameters, if: :devise_controller?
 ....

 def configure_permitted_parameters
 devise_parameter_sanitizer.for(:account_update) { |u| 
  u.permit(:password, :password_confirmation, :current_password) 
   }
  end
end

Upvotes: 2

Related Questions