Rails 3 /devise seems to ignore custom controller

2019-07-27 08:23发布

问题:

Using devise with Rails 3 app, I have read wiki/docs on how to customise the after sign up route, I am using confirmable module, so I think I need to override after_inactive_sign_up_path_for

I think I've done it all right, but it is completely ignoring my custom controller and still routing to the root_path after sign up. Driving me nuts.

My registration is using User model, I have copied the views for devise using the generate task; if i move them to views/registrations devise falls back to the default views (in the gem I guess), so it seems not to be 'noticing' my controller

I have this in my routes:

devise_for :users, :controllers => { :registrations => "registrations" }
match 'sign_up_done' => 'home#sign_up_done', :as => :after_sign_up

Here is my controller: (controllers/registrations_controller.rb)

class RegistrationsController < Devise::RegistrationsController
  def after_inactive_sign_up_path_for(resource)
    after_sign_up_path
  end 
  def after_sign_up_path_for(resource)
   after_sign_up_path
  end
end

(Added after_sign_up_path_for just in case, using confirmable)

It just seems to completely ignore my controller, is the naming wrong? Thanks for any input!

回答1:

I think your folder structure may have problems. try this structure: ( it's the same as those in Gem folder)

app/controllers/devise/registrations_controller.rb
app/views/devise/registrations/new.html.erb
app/views/devise/registrations/edit.html.erb

and the controller file looks the same as it is declared in the gem folder:

#app/controllers/devise/registrations_controller.rb

# NOT: class RegistrationsController < Devise::RegistrationsController  , 
# since you are "overwriting" it. 
class Devise::RegistrationsController < DeviseController

  def after_inactive_sign_up_path_for(resource)
    #...
  end 
end