'Generating Devise Controllers - Rails Devise
I am trying devise for the first time.I am following the link:https://github.com/plataformatec/devise. Here,i have executed the command:
rails generate devise MODEL
when i have executed this,the model and view parts are created.When i checked the routes,I have noticed that there is a controller created with the name:MODEL.but i didnot find the controller in the project.My query is how can we find whether a controller is generated or not and use that controller in the project. Thanks in advance.
Solution 1:[1]
running
rails generate devise MODEL
when using the Devise gem will not create the controllers for you.
In your case, if you want to change any methods in the Devise controllers, you may want to create your own controller that inherits Devise controllers.
For example, changing the devise registration controllers to allow first and last name would require you to create your own controller under app/controllers/MODEL/registrations_controller.rb
Link to Devise controllers here
class MODEL::RegistrationsController < Devise::RegistrationsController
before_filter :configure_permitted_parameters
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name])
end
end
and instructing your routes.rb to use the controller
devise_for :MODEL, :controllers => { :registrations => "MODEL/registrations" }
Solution 2:[2]
Replace MODEL with User like
rails generate devise User
It will generate User model under app/modeld/user.rb and user controller under app/controllers/users_controller.rb
run migration to add user table under database using command:
rake db:migrate
Solution 3:[3]
Short answer.
rails generate devise:controllers users
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | puneet18 |
| Solution 3 | Jin Lim |
