Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6683789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:51:45+00:00 2026-05-26T04:51:45+00:00

I have a Rails 3 app and am implementing a profile completeness sort of

  • 0

I have a Rails 3 app and am implementing a profile completeness sort of feature. When the user is logged in the app should show him/her progress on making a “complete” profile. To wit I am using a singleton class populated with requirements at app initialization. The singleton has an array, @requirements. It is correctly populated using my initializer. When I hit the ProfileController the requirements display. However, after the first, subsiquent requests to ProfileController#completeness list no @requirements. The array on the singleton is empty. I believe the singleton is not returning the same instance across controller requests. Where am I going wrong here?

Note: this class just holds rquirements, not a particular user’s progress towards fulfilling them. Requirements rarely change so I want to avoid a database lookup.

# lib/profile_completeness.rb
require 'singleton'

class ProfileCompleteness

  include Singleton
  include Enumerable

  attr_reader :requirements

  def add_requirement(args)
    b = Requirement.new(args)
    @requirements << b
    b
  end


  def clear
    @requirements = []
  end


  def each(&block)
    @requirements.each { |r| block.call(r) }
  end


  class Requirement
    # stuff
  end

end

–

# config/initializers/profile_completeness.rb
collection = ProfileCompleteness.instance()
collection.clear

collection.add_requirement({ :attr_name => "facebook_profiles",
                             :count => 1,
                             :model_name => "User",
                             :instructions => "Add a Facebook profile" })

–

class ProfileController < ApplicationController
  def completeness
    @requirements = ProfileCompleteness.instance
  end

end

–

<!-- app/views/profile/completeness.html.erb -->
<h2>Your Profile Progress</h2>
<table>
  <%- @requirements.each do |requirement|
        complete_class = requirement.is_fulfilled_for?(current_user) ? "complete" : "incomplete" -%>

    <tr class="profile_requirement <%= complete_class -%>">

      <td>
        <%- if requirement.is_fulfilled_for?(current_user) -%>
          &#10003;
        <%- end -%>
      </td>

      <td><%= raw requirement.instructions %></td>

    </tr>
  <%- end -%>
</table>
<p><%= link_to "Profile", profile_path -%></p>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:51:46+00:00Added an answer on May 26, 2026 at 4:51 am

    this is not going to work (multi-threading, different rails workers etc.) you can’t expect to land in the same rails app thread on every request. If your server crashes, all progress is lost! So the way to go for persisting data (permanently) across requests/sessions is a database.

    Model your completeness tracker as a Model and store it in your database.

    Another solution is to use the Rails Application Cache.

    Set a Key/Value pair:

    Rails.cache.write('mykey', 'myvalue');
    

    Reading:

    cached_value = Rails.cache.read('mykey');
    

    Read more about Rails Cache

    If you want a solution for big data sets and fast access, I recommend you to use redis:

    Here is a good article especially the section “Using Redis As Your Rails Cache Store” and look through the section “Redis Related Gems”.

    The important thing is the key/value data structure, I’d go for keys like

    progress:user_id:requirements = [{ ...requirement 1 hash...}, {..requirement 2 hash.. }]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails app implementing a game, so it's expected that a player
I have a rails app, where I have 2 models, user and notice. A
I have a Rails 2.3.x app that implements the act_as_authentic in User model and
I have a Rails app set up so that when a user uploads an
I have a rails 3 app that creates a sessions with: cookies.permanent.signed[:remember_token] = [user.id,
I have a rails app that I have serving up XML on an infrequent
I have a Rails app that I have successfully tested with Mongrel and Webkit.
I have a Rails app that I need to deploy. Here are the facts:
I have a rails app that has picked up a bit of traction, but
I have a Rails app that sets a cookie and does a redirect to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.