Search code examples
ruby-on-railsdeviseruby-on-rails-plugins

How do I implement gradual engagement using Devise and Rails 3?


I'm trying to implement a delayed-signup (aka delayed authentication aka gradual engagement) website flow using Devise + Rails.

By gradual engagement, I mean

"Don't make the user sign in until she absolutely has to, but let her play around and be remembered on the site"

I'm looking for a simple way to do this using devise. I feel like this is something many others have had to do, but I haven't found documentation on it.

The following approach sounds ok in my head, so I'm going to start with it:

  1. Create users that are only "rememberable"
  2. When certain pages are accessed, require that these users have more data on them, like a username and password, via something like "before_filter :authenticate_user!" in the appropriate controllers.

Does this approach make sense? Is there a better one? Do you have an implementation of a gradual engagement approach to signup/registration forms using Devise + Rails that you're willing to share?


Solution

  • I think the point of the article you gave us is to say:

    • only ask for sign up if necessary.

    What does this mean?

    Let's take an example. You're an e-commerce web site.

    When does the customer has to sign up "at last"? During checkout. Never before. So you don't have to store, or remember anything about the user. Devise is never, never used here.

    How do you manage the shopping cart of an unsigned in/up user? I'd say database, with session Id as primary key. Or You could store all the items ids in cookie, for later use.

    In your code, if you have an action called checkout, just set in your controller a before_filter authenticate_user!, :only => [:checkout]

    But maybe you have some constraints, like being able to keep your user's nickname without signing him up for example?