Custom action for developing a registration controller that receives a null resource

Basically, I want to have two separate actions for changing the password and changing the email address instead of one.

I updated my routes to point to my new controller, which inherits from Devise :: RegistrationsController.

My .rb routes:

devise_for :users, :controllers => { :registrations => "registrations" } devise_scope :user do get "/users/password" => "registrations#change_password", :as => :change_password end 

My registrations_controller.rb

 class RegistrationsController < Devise::RegistrationsController def change_password end end 

My app / views / devise / registration / change _password.html.erb

 <%=debug resource%> 

Which gives me zero.

What am I missing here?

Thanks!

+6
source share
2 answers

There is an authenticate_scope! method in the development of the built-in registrations_controller.rb authenticate_scope! that creates the resource object you are looking for. It is executed by prepend_before_filter , but only for certain methods:

 class Devise::RegistrationsController < DeviseController ... prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]` 

So, you just need to tell your user controller to run this filter using your change_password method:

 class RegistrationsController < Devise::RegistrationsController prepend_before_filter :authenticate_scope!, :only => [:change_password] def change_password end end 
+10
source
 class RegistrationsController < Devise::RegistrationsController def change_password super @resource = resource end end 

application / views / invent / registration / change_password.html.erb

 <%=debug @resource%> 
-3
source

Source: https://habr.com/ru/post/919292/


All Articles