Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would create a <code>Profile</code> model which is automatically created for any user that visits your site and adds the first favourite, rates the first item, etc. The <code>Profile</code> should be saved to your database including a suitably random and unique string. This string can be stored as a cookie on the client side, and will be used later to retrieve your profile. It should be random and long enough so that you cannot easily tamper with your cookie and get other anonymous people's profiles, but this is not entirely avoidable (so beware you store no sensitive data in anonymous profiles!).</p> <p>Once a user registers, you can associate their <code>Profile</code> with their new <code>User</code> record and remove the cookie and the unique string identifier. You can now simply retrieve their profiles when they log in, based on their <code>User</code> record.</p> <p>The <code>Profile</code> model can contain any information you would like to store.</p> <p>If you want to differentiate between registered users and anonymous users, you could create an <code>AnonymousProfile</code> model and a <code>Profile</code> model (each with different attributes), and simply copy over all data from the anonymous profile to the user profile when someone registers.</p> <p><strong>Update:</strong> Throughout your application you can decide to only use this information when a user is logged in. You might define a <code>before_filter</code> that grabs the current user, and only if there is an actual user logged in, do you use the profile data:</p> <pre><code>class ApplicationController &lt; ActionController::Base before_filter :fetch_user_data def fetch_user_data @current_user = ... # Work your magic to get current user end private def current_profile @current_user and @current_user.profile # Use profile association end end </code></pre> <p>Somewhere in a controller action:</p> <pre><code>if current_profile # Do stuff with current_profile # Only available to registered users... end </code></pre> <p>You can later change the implementation of <code>current_profile</code> if you change your mind and want anonymous profiles to have effect for your anonymous users.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload