How to edit and customize devise view and controller
After introducing devise, I want to prepare a view that looks bland and is only in English. You need to edit and customize the devise controller. I will briefly introduce the method in such a case.
ruby 2.6.5 rails 6.0.0 devise 4.7.3
devise installed model generated Routing is set everywhere
Let's implement it.
Open config / initializers / devise.rb. Enable config.scoped_views.
# ==> Scopes configuration # Turn scoped views on. Before rendering "sessions/new", it will first check for # "users/sessions/new". It's turned off by default because it's slower if you # are using only default views. config.scoped_views = true #← Default is false#
Restart the Rails server.
Generate a devise controller.
$ rails g devise：controllers users
The lecture at this time is rails g devise: controllers model name is. This time I'm using the devise model as user, so I'll use that name. app > controllers > users > You will have a file under. For example, if you want to customize the controller related to user registration, edit the registrations_controller.rb file.
One thing to note here is the routing settings. Described in routing
[Controller name] # [Action name] And the actual [Controller] # [Action]
If it is different, it is natural, but it does not work. Therefore, it is recommended to check it carefully with rails routes etc.
Generate and edit the devise view file.
$ rails g devise:views
app > views > devise > A folder will be created directly under devise.
For example, if you want to edit the registration screen, edit the file in the registrations directory.
The thing to note here is the view filename. In devise, if you do not specify the transition destination with render or redirect_to, it will transition to the method name after processing of the controller. So you need to match each name.
Introduced the generation / customization of contoroller and the generation / editing of view files. Using devise's controller has the advantage that you can automatically use the functions that you have by default. However, on the other hand, even if you make a mistake, devise will work behind the scenes, so you will not behave as you want and you will not get an error. For that reason, it is recommended to pay attention to how the routing, controller, and view are following.
I am a beginner in programming, but I am posting an article in the hope that it will help people who want to become engineers as well as myself. See you next time ~