mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Customize Paths And Helpers For Devise Routes as a rails til
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
||||
|
||||
_1006 TILs and counting..._
|
||||
_1007 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -616,6 +616,7 @@ _1006 TILs and counting..._
|
||||
- [Convert A Symbol To A Constant](rails/convert-a-symbol-to-a-constant.md)
|
||||
- [Creating Records of Has_One Associations](rails/creating-records-of-has-one-associations.md)
|
||||
- [Custom Validation Message](rails/custom-validation-message.md)
|
||||
- [Customize Paths And Helpers For Devise Routes](rails/customize-paths-and-helpers-for-devise-routes.md)
|
||||
- [Customize The Path Of A Resource Route](rails/customize-the-path-of-a-resource-route.md)
|
||||
- [Delete Paranoid Records](rails/delete-paranoid-records.md)
|
||||
- [Demodulize A Class Name](rails/demodulize-a-class-name.md)
|
||||
|
||||
30
rails/customize-paths-and-helpers-for-devise-routes.md
Normal file
30
rails/customize-paths-and-helpers-for-devise-routes.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Customize Paths And Helpers For Devise Routes
|
||||
|
||||
Wih a default Devise setup (`devise_for :users`), the sign up/in/out routes are
|
||||
located at `/users/sign_up`, `/users/sign_in`, and `/users/sign_out`. And the
|
||||
path helpers are `new_user_registration_path`, `new_user_session_path`, and
|
||||
`destroy_user_session_path`, respectively.
|
||||
|
||||
These can be customized in `config/routes.rb` by opening up the `devise_scope
|
||||
:user` block and re-specifying the routes of interest.
|
||||
|
||||
```ruby
|
||||
Rails.application.routes.draw do
|
||||
devise_for :users
|
||||
devise_scope :user do
|
||||
get 'sign_up', to: 'devise/registrations#new'
|
||||
get 'sign_in', to: 'devise/sessions#new'
|
||||
delete 'sign_out', to: 'devise/sessions#destroy'
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
These three custom routes override the paths and helps I described above like
|
||||
so:
|
||||
|
||||
- `sign_up_path` -> `/sign_up`
|
||||
- `sign_in_path` -> `/sign_in`
|
||||
- `sign_out_path` -> `/sign_out`
|
||||
|
||||
I find these path helpers easier to work with and I like the UX of
|
||||
registration/session paths not nested under `/user`.
|
||||
Reference in New Issue
Block a user