Let’s Build with Ruby on Rails – Extending Devise – Custom Routing
Tags: rails, ruby, tutorial, video
Published: 2019-07-17 04:13:33

---
title: Let’s Build with Ruby on Rails – Extending Devise – Custom Routing
published: true
tags: rails, ruby, tutorial, video
canonical_url: https://web-crunch.com/lets-build-with-ruby-on-rails-extending-devise-custom-routing/
---

Continuing my Let’s Build with Ruby on Rails – Extending Devise series I take a look at Devise custom routing options within a Ruby on Rails application harnessing the Devise gem.

[View the source code](https://github.com/justalever/extending-devise-custom-routing)

Download the Kickoff Tailwind Template I reference in this tutorial (optional):  
[https://github.com/justalever/kickoff\_tailwind](https://github.com/justalever/kickoff_tailwind)

{% youtube 5T0LK02wRSE %}

In this guide, you’ll learn how to use my `kickoff_tailwind` template (linked above) to install and create a new Ruby on Rails app. Among many other configurations, the template sets up Devise for quick use immediately. Out of the box some defaults come with devise but I add a couple of new fields (username, name) to each given user account.

Customizing routing is quite easy in the context of the devise gem. A basic install on a fresh ruby on rails app might look like the following:

```ruby
Rails.application.routes.draw do
  devise_for :users # default custom method for rendering all routing
  root to: "home#index" # devise requires some sort of root option to redirect back to
end

```

Extending the default paths from say `/users/sign_in` or `/users/sign_up` might be something you want to customize based on your own apps logic and/or branding. Doing so it pretty straight forward. In the end I made the following changes.

```ruby
Rails.application.routes.draw do

  devise_for :users,
    path: '', # optional namespace or empty string for no space
    path_names: {
      sign_in: 'login',
      sign_out: 'logout',
      password: 'secret',
      confirmation: 'verification',
      registration: 'register',
      sign_up: 'signup'
    }

  root to: 'home#index'
end

```

Above you can see how the defaults are overwritten with string values which essentially just update the URL pathnames accordingly. You don’t need to modify view or controller names in your app which is great but also kind of confusing as most of the time those things match. I’ve worked with Devise long enough for this issue to not affect me a great deal but it might be something worth considering for your own projects.

### The Series So Far

- [Let’s Build: With Ruby on Rails – Extending Devise Series – Adding Custom Fields](https://web-crunch.com/extending-devise-custom-fields)
- [Let’s Build: With Ruby on Rails – Extending Devise Series – Confirmation Emails](https://dev.to/justalever/let-s-build-with-ruby-on-rails-extending-devise-series-confirmation-emails-egf)

### Shameless plug time

[![](https://i1.wp.com/web-crunch.com/wp-content/uploads/2019/01/YouTube-Promo3.jpg?resize=3840%2C2160&ssl=1)](http://hellorails.io)

I have a new course called [Hello Rails](https://hellorails.io). Hello Rails is a modern course designed to help you start using and understanding Ruby on Rails fast. If you’re a novice when it comes to Ruby or Ruby on Rails I invite you to check out the site. The course will be much like these builds but a super more in-depth version with more realistic goals and deliverables. [Sign up to get notified today](https://hellorails.io/)!

Follow [@hello\_rails](https://twitter.com/hello_rails) and [myself @justalever](https://twitter.com/justalever) on Twitter.

The post [Let’s Build with Ruby on Rails – Extending Devise – Custom Routing](https://web-crunch.com/lets-build-with-ruby-on-rails-extending-devise-custom-routing/) appeared first on [Web-Crunch](https://web-crunch.com).