devise

Decorating Sorcery's current_user with Draper

I already wrote about how to apply your decorator to the current_user when you’re using Devise. However, the trick is a bit different when applied to Sorcery. Instead of being nil when no user is signed in, Sorcery uses an explicit false value, no nil. In your ApplicationController at app/controllers/application_controller.rb add this: def current_user UserDecorator.decorate(super) unless super == false end I’m using the most recent version of Draper by the way.

Decorating Devise's current_user with Draper

I’ve become a big fan of decorators, especially Draper. Decorators allow you to move view related functionality for your models in to separate decorator classes. This keeps both your models and views clean and readable. Anyway, if you use Devise you’re provided with a current_user helper. However, this helper returns an instance of User - without your decorators. To enable decorators for your current_user by default, simple add this to app/controllers/application_controller.

Rails 3 + Devise + Uploadify = No Flash Session Hacks

Uploadify is a great project to provide file uploads in your project. The problem is, it’s written in flash. Besides the point that it is flash, there’s something else that has been bothering me a lot: sessions. ~ The problem is like this. When a browsers opens a connection to your Rails app, it has a session. Normally, session information is stored a cookie that is sent with every request. This session also contains information needed for you to stay logged in as a particular user.