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

  • Home
  • SEARCH
  • 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 3935830
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:52:31+00:00 2026-05-19T23:52:31+00:00

Ok, I have a Rails 3 application and I am using CouchDB as my

  • 0

Ok, I have a Rails 3 application and I am using CouchDB as my primary database to take advantage of it’s replication capabilities.

Anyway, what I want to do is store some configuration type stuff in 1 document in the database and load the values of this configuration file one time when the app starts up in production and reload ONLY if the user goes to the admin panel and explicitly requests it to happen. I was thinking by touching a URL to clear the loaded config or something.

My thought was that I would just create a before_filter in application_controller, but since I am new to rails, I didn’t know if this was the proper way to do this.

before_filter :get_config

private

def get_config
  @config = Config.get('_id')
end

Clearly this would run every request, which I don’t want or need. Is there a way to save the config output so I don’t have to fetch it every single request, or is there a better way to do this.

Thanks in advance.

  • 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-19T23:52:32+00:00Added an answer on May 19, 2026 at 11:52 pm

    Actually I am writing an article about the proper way of using global variables in rails. This seems to be the case to introduce global variables, as their values are shared across different users.

    In your before_filter, try this:

    def get_config
      $config ||= Config.get('_id')
    end
    

    This would call Config.get('_id') only if $config is false or nil. Otherwise, $config wiil remain unchanged.

    The tricky part is global variables (starting with a $ sign) alive in the whole application. So $config is available everywhere (and that would be a problem for careless design!)

    Another point is, as you said you are new to rails, I do suggest you to read more about global variables before you use it and DO NOT ADDICT to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails application using Restful authentication and declarative authorization. I have some
I have Ruby on Rails application which is using MySQL database. For now I'm
I working on Ruby on Rails application using a PostgreSQL database. I have heard
I have one rails application, using omniauth. And also save token in my database.
I have an existing Rails 3 application using ActiveRecord, and I want to switch
I have a rails application in which I implemented some feature. Now I want
I have a rails application that allows searches using longitude and latitude. I have
I have a Rails 3.2.2 application using Ruby version 1.9.2. I have created basic
I have created a blog application using Ruby on Rails which includes the ability
I am using haml with my rails application and i have a question how

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.