VIVAHATE

November 2011

Jacques’ Seafood Bread

A recipe from Jacques Pépin.

Happy cooking!

Duck w/ Candied Kumquat

Photo by Jameel

Grilled Chicken w/ Mango Salsa

Photo by Jameel

Dumplings

Photo by Jameel

Login Redirection with Rails 3.1, Devise, and CanCan

This approach satisfies a few common requirements:

  • Requests by non-signed in users should redirect to the sign in page. Post sign in, the user should be redirected to their original destination.
  • Requests by signed in users to resources which they cannot access (CanCan::AccessDenied) should redirect to an error page.

Modify Application Controller

First, update your application controller.

Create Error View

Create app/views/error/403.html.erb. The contents of the file are unimportant.

Create Session Controller

Generate a new session controller:

rails g controller Sessions

Here’s how it should look:

Update Routes

Update your routes so Devise knows to make use of your new sessions controller.

Move New Session View

Move your new session view (if you generated them) from /app/views/devise/session/new.html.erb to /app/views/session/new.html.erb.

HINT: Set config.consider_all_requests_local in /config/environments/development.rb to false to test this while in development.