Render Custom views instead of default Devise views- Rails
Overriding the default Devise’s views
is simple and straight forward, what we need to do is just generate those views in our app/views
folder by the following single command.
rails g devise:views
The following views
are generated.
app/views/devise/confirmations
app/views/devise/mailer
app/views/devise/passwords
app/views/devise/registrations
app/views/devise/sessions
app/views/devise/shared
app/views/devise/unlocks
No other changes are necessary.
Or if you have already done it,you need to move folders inside app/views/devise
Can't override default devise gem views
For a custom login view, when you're using the default User
devise resource, I think all you need is to create app/views/devise/sessions/new.html.erb
. And, just for the moment, let's forget about the CRUD interface. And undo those config/initializers/devise.rb
settings. Just see if you can get that working.
Second devise model not using generated views
By simply putting the views there Devise won't use them. You would need to point Devise::RegistrationsController
to the right controller which has these views, which you can do by calling this:
devise_for :reps, :controllers => { :registrations => "reps/registrations" }
This needs to have a new controller defined at app/controllers/reps/registrations_controller.rb
:
class Reps::RegistrationsController < Devise::RegistrationsController
end
You would then have the views in the right directory for this controller to use.
Customizing Devise views in Rails
Your route signup
or devise/registrations#new
will render the viewviews/devise/registrations/new.html.erb
. It sounds like you made
changes to views/user/registrations/new.html.erb
, which would explain
why you dont see the changes made since its not being rendered.
You will either need to create a user/registrations_controller.rb
that
extends from Devise::RegistrationsController
and point your /signup
route to user/registrations#new
, or you can just make your changes
directly to views/devise/registrations/new.html.erb
Same idea applies to your login (devise/sessions
) pages.
Hope this helps.
Where is the code that Devise generates?
Using Devise, you're able to generate the templates which Devise depends on for logins, password resets, etc. using the following command:
rails generate devise:views
This will create copies of the templates for Devise in your views
directory.
For controllers, you can access/override their functionality by subclassing them in your own code. They're under the Devise
namespace:
class NewRegistrationsController < Devise::RegistrationsController
# do stuff here
end
Then point the router to use this new controller:
devise_for :users, controllers: { registrations: 'new_registrations' }
The code for the controllers can be found in Devise's source code - you can reference it to better understand what each controller is doing.
Hope that helps!
Related Topics
How to Find the Most Recently Modified Folder in a Directory Using Ruby
Ruby Symbol#To_Proc Leaks References in 1.9.2-P180
Ruby on Windows7 - Could Not Find Gem
Exclude Some Ids from Result in Rails Activerecord
Regex to Match Mm/Dd/Yyyy Hh:Mm:Ss Am or Pm
Any Ruby Library to Inspect What Are the Arguments That a Certain Methods Take
Validating Date Format Using Regular Expression
Ruby 1.9 Ramaze App Failing with "Illegal Instruction"
Byebug Fully Supports Windows or Not
Rails Not Working for New Project. Showingerror " Superclass Mismatch for Class Cipher (Typeerror)"
Reverse a String Each Two Characters with Ruby
Hiding an Attribute in an Activerecord Model
Mechanize and Ntlm Authentication
How to Fix Ruby Script Which Fails with Encoding Error: "\Xd8" on Us-Ascii
Ruby Selenium Web Driver: How to Count Child Element Nodes of a Specific Node