简体   繁体   中英

Rails Devise Override Registration Controller

I am working with Devise and I am trying to override the registrations controller.

I have followed posts on here with no luck.

This is what I have:

 class AccountsController::RegistrationsController < Devise::RegistrationsController
  def new
    super
  end
 end

   devise_for :accounts, :controllers => {:registrations => "accounts/registrations"} do
     get "welcome" => "accounts#new", :as => :new_account
   end

I also created an account folder in views and added the new view.

I receive the following error:

 app/controllers/accounts_controller.rb:1:in `<top (required)>'

@Brian is correct it will work but you want your code have to work just change:

class AccountsController::RegistrationsController < Devise::RegistrationsController

to:

class Accounts::RegistrationsController < Devise::RegistrationsController

Then create an accounts folder in the controller folder and place this file to that folder.

Mine was a little different, but this solved the problem. Override devise registrations controller

  class RegistrationsController < Devise::RegistrationsController
def new
    @test = "test"
    super
end
  end

The I added the following to my views registrations/new.html.erb

Then:

  devise_for :accounts, :controllers => {:registrations => "registrations"} do
  get "welcome" => "registrations#new", :as => :new_account
  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