I’ve been working on a Rails application in which I’m using Devise for the user account and authentication management library.

Out-of-the-box, Devise will throw up a browser dialog for authentication if the user fails properly login. For this particular project, I wanted to get rid of the dialog and exclusively use pages.

There were a number of small changes that I had to make to get this to work. Google wasn’t the biggest help, so here’s what I had to do in my specific case:

In initializers/devise.rb, verify that you have this line:

config.http_authenticatable = false

In config/routes.rb, make sure that the following line is present:

devise_for :users

This is what’s responsible for generating authentication routes for your User model.

When a user returns to the site, I want them to be taken to what is essentially their homepage; however, if they aren’t logged in, I want to redirect them to the authentication path first.

For a single user, I also had to setup a Devise route for a user:

devise_for :user do
  root :to => "devise/sessions#new"
end

Finally, I added a root route for the user namespace:

namespace :user do
  root :to => "categories#index"
end

This is what allows the user to continue moving through the system after having to login.

Lastly, I recommend placing the follow elements at the top of your application’s layout:

<p class="notice">
  <%= notice %>
</p>

<p class="alert">
  <%= alert %>
</p>

This will display all notices and alerts generated via the login process as well as provide an area for messages to display after users have logged into the system.

Category:
Notes
Tags:

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.