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 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

Ask A Question

Stats

  • Questions 156k
  • Answers 156k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Uploadify - http://www.uploadify.com/ - easy to implement, easy to customize,… May 12, 2026 at 10:56 am
  • Editorial Team
    Editorial Team added an answer The above solution did not work for me. But I… May 12, 2026 at 10:56 am
  • Editorial Team
    Editorial Team added an answer I would recommend making the whole thing more data driven.… May 12, 2026 at 10:56 am

Related Questions

I have an XML reader class which I initialize with a URL - (id)initWithURL:(NSURL
Okay, so I have two classes, call them A and B--in that order in
Coles Notes version: index.php?map_id=foo is loaded into iframe on www.not-my-domain.com. index sets SESSION['map_id'] =
I've written an abstract base class for unit tests that sets up just enough

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.