How to implement gradual interaction with Devise and Rails 3?

I am trying to implement a delayed web stream thread (e.g. delayed authentication or gradual interaction) using Devise + Rails.

By gradual interaction , I mean

"Do not force the user to enter while it is absolutely necessary, but let it play around and be remembered on the site"

I am looking for an easy way to do this using devise . I feel that this is what many others should have done, but I did not find the documentation on it.

The following approach sounds fine in my head, so I'll start with it:

  • Create users who are only "remembered"
  • When accessing certain pages, these users need to have more information about them, such as username and password, through something like "before_filter: authenticate_user!" to the appropriate controllers.

Does this approach make sense? Is there a better one? Do you have a step-by-step approach to registering registration / registration forms with Devise + Rails that you are willing to share?

+4
source share
3 answers

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

  • request only if necessary.

What does it mean?

Take an example. You are an e-commerce website.

When should a customer finally register? During checkout. Never before. Therefore, you do not need to store or remember anything about the user. Devise is never, never used here.

How do you manage the shopping cart for an unsigned user / up? I would say a database with a session id as a primary key. Or you can save all ids elements in a cookie for later use.

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

But maybe you have some limitations, for example, the ability to save your user nickname without signing it?

+2
source

One alternative is to register only by email, and then send an email with a special link to complete the registration later / return them to your account. There, an email development tutorial is actively supported only at:

https://github.com/plataformatec/devise/wiki/How-To:-Email-only-sign-up

I used this tutorial for a site that I did some time ago, where we only asked for an email address for registration, and then sent emails to complete registration / add a password.

+1
source

You can store all unsigned user data in cookies and transfer them to the database after the user logs in if you need.

0
source

Source: https://habr.com/ru/post/1335903/


All Articles