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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:06:48+00:00 2026-05-20T15:06:48+00:00

I have a question about setting up constants in Rails project. From Dan Chak’s

  • 0

I have a question about setting up constants in Rails project.

From Dan Chak’s Enterprise Rails book, he explains that constant lookup code like below gets executed only once when the app starts. However, looking at the log, I think it gets run every time I use the constant.

class Role < ActiveRecord::Base
  USER = Role.find_by_key('user')
  ADMIN = Role.find_by_key('admin')
end

This definitely allows cleaner code as I can do something like:

current_user.role = Role::ADMIN

As an alternative, I read about ActiveSupport::Memoizable, but I want to confirm this setup results in multiple db lookup before changing my code around.

Thanks for your input!

  • 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-20T15:06:48+00:00Added an answer on May 20, 2026 at 3:06 pm

    That code will only get executed once each time your environment is loaded. This will happen often in development and test environments, but only once each time an app server is spawned in production.

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

Sidebar

Related Questions

I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The
Following on from this question about setting Culture, I have a similar issue with
I have a routing question about rails 3, and setting up a conditional :root
I have a question about setting the style attributes for a data cell in
I have question about sending emails from MVC3 application. I already read for exmple
I'm setting up a project that uses SASS, which uses FSEvents to keep from
I am new to Android development and I have a question about setting weight
I have a question about Eclim and setting it up basically. I've gone through
i have a question about memory management.I have an instance variable that I previously
I'm following the NerdDinner tutorial for MVC and have a question about setting up

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.