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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:38:16+00:00 2026-05-11T05:38:16+00:00

I have an initializer which sets a default that is used throughout the app.

  • 0

I have an initializer which sets a default that is used throughout the app. The value is an ActiveRecord model, I’m essentially caching it for the lifetime of the app:

@@default_region = Region.find_by_uri('whistler') 

The record is guaranteed to be in the database: it’s fixture data which is referenced by other models. This works fine, except in the test environment where the database is purged before every test run. (I’m running on edge rails and I think that’s recent behavior: I used to be able to insert the data manually and keep it between test runs.) I also have the record in my regions.yml fixture file, but fixtures aren’t loaded until after the rails initializer is done.

What’s the right way to deal with such a dependency on fixture data? Or is there a better way to structure this? I’d rather not use a before_filter because there’s no sense reloading this on each request: it will not change except on a different deployment.

  • 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. 2026-05-11T05:38:17+00:00Added an answer on May 11, 2026 at 5:38 am

    I’d put something like this in region.rb:

    def self.default_region   @@default_region ||= Region.find_by_uri('whistler') end 

    Then you can access it as Region.default_region wherever you need it, and it’s only looked up once – the first time it’s called – and by then the fixtures will be in place.

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

Sidebar

Related Questions

we have model helper (used by several different models) called set_guids that sets self.theguid
I have a singleton initializer which is a class method. I want to set
I have a Bash script that basically initializes an application and sets parameters. One
I have a simple class which sets up NserviceBus for a legacy windows service.
I have a class whose instances have attributes that are containers which themselves contain
I have a view controller class called PresidentsViewController that sets up data in a
I have 1 abstract class that is calling a static method which up until
I have a web application which has two servlets that exchange information through context
Say I have a listbox lb, which I initialize using: lb.DataSource = wordList \\wordList
I have a 2-dimensional jagged array (though it's always rectangular), which I initialize using

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.