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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:41:04+00:00 2026-06-15T21:41:04+00:00

My question is seemingly simple but has been pretty elusive. I want one value

  • 0

My question is seemingly simple but has been pretty elusive. I want one value that can be called anywhere in the application – it’s a minimum value we are using for validations in the model, we want to inform the user of that value, etc.

So far, I have done the following:

In config/initializers, I created a new .rb file (under suggestion I found on another thread):

minimum = 15

and only got that it couldn’t be found after starting rails server.

I found a strange suggestion to put the value in en.yml as minimum: 15, same issue as above.

Obviously, application helper and controller won’t help as I need the value in my models. I did however find one solution, which was to put it in the class Application in config/application.rb:

config.after_initialize do
    ::Minimum = 15
end

and afterwards call it like this:

MyApp::Application::Minimum

Obviously, this solution, while it does work, isn’t ideal. If I could find a way to alias MyApp::Application::Minimum as just “minimum”, I’ll be completely satisfied, but getting it done in the initializers is, from what I’ve heard, a better solution.

  • 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-15T21:41:05+00:00Added an answer on June 15, 2026 at 9:41 pm

    You can stick something in a model if you want and call it from anywhere:

    Couriers = %w[TNT UPS RoyalMail Bike Hand Pigeon Other]
    

    But I prefer putting them in a yaml file.

    Create a config.yml file in your configs directory and put your vars in there:

    defaults: &defaults
    
       node_1: '10.8'
       node_2: '10.9'
       node_3: '10.0'
    
       whatever: 1
       thereis: 2
    
    development:
      <<: *defaults
    
    playground:
      <<: *defaults
    
    production:
      <<: *defaults
    
    poststaging:
      <<: *defaults
    
    test:
      <<: *defaults
    

    Load the config file using something like this in your initializers directory. Create a file in /config/initializers called ‘load_vars.rb’ and put the following in there:

    SETTINGS = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env]
    

    You’ll have to restart your server after changing these though.

    — EDIT —

    To use these variables, you can load with something like this from your model, controller, views:

    SETTINGS['var_1']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple question, but I haven't seen anything in the jwplayer javascript API that
Apologies for the seemingly simple question, but I can't seem to find a solution
This is a simple question, and a seemingly simple task but I can't find
I have a seemingly simple question, but can't find the answer. I have a
Seemingly a simple enough question, but I cannot work it out. I want to
I know this question has been asked and seemingly answered a gazillion times over
I have a seemingly simple requirement, but i can't figure out how to write
A seemingly simple question...how can I return a list of days for any specified
So, this is a seemingly simple question, but I'm apparently very very dull. I
A simple question: Why does this the first code work but the seemingly identical

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.