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 8320167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:33:58+00:00 2026-06-08T22:33:58+00:00

I’ve defined custom configuration variables in my rails app (APP_CONFIG hash). Ok, now how

  • 0

I’ve defined custom configuration variables in my rails app (APP_CONFIG hash). Ok, now how can I use these variables in my models? Directly calling APP_CONFIG[‘variable’] in models its a not rails way! For example I can use these models without Rails environment. Then APP_CONFIG not be defined.

ATM I use model observer and assign global config variables with instance variables, like this:

def after_initialize model
  Mongoid.observers.disable :all do
    model.user_id = APP_CONFIG['user_id'])
    model.variable = User.find(model.user_id).variable
  end
end

But this solution looks like a monkey patch. There is better way?

Or I should keep it simplest and can just define APP_CONFIG hash in new app (not Rails app)?

  • 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-06-08T22:34:00+00:00Added an answer on June 8, 2026 at 10:34 pm

    I’d use dependency injection. If you have an object that needs various config values, you could inject the config object through the constructor:

    class Something
      def initialize(config = APP_CONFIG)
        @config = config
      end
    end
    

    And if the config is only needed for a single method, simply pass it to the method:

    def something(config = APP_CONFIG)
      # do something
    end
    

    Ruby evaluates parameters when the method is called. The default value allows you to use your config object in development/production without having to manually pass it to the methods and to use a stub instead of the actual config in your tests.

    Instead of defining another global variable/constant, you could also use the Rails config instead:

    def something(config = Rails.config)
      # do something
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.