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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:10:38+00:00 2026-05-24T09:10:38+00:00

I am using Ruby on Rails 3.0.9 and I am developing a plugin. I

  • 0

I am using Ruby on Rails 3.0.9 and I am developing a plugin. I would like to know if it “right” to state a constant value like this (note the ||):

CONSTANT_NAME ||= "Constant_value"

Is it a proper\ensured approach the above?

P.S.: I would like to make that in order to avoid to log warning messages like the following in the Apache error_log file:

/<RAILS_ROOT>/vendor/plugins/sample_plugin/lib/sample.rb:52: warning: already initialized constant CONSTANT_NAME
  • 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-24T09:10:39+00:00Added an answer on May 24, 2026 at 9:10 am

    It seems clumsy to define constants in several places. I even don’t see why you need this. A better solution could be provided if you give more context.

    Anyway, a trick could be to create a constant as a Hash. Then anywhere in you app you can define/redefine the it’s content. Something like:

    CONFIG = { :foo => "bar" } 
    

    Then anywhere else:

    CONFIG[:foo] ||= baz
    

    Edit:

    With your gem context provided, I’d say you’d better avoid to include the constant at the model level: you won’t have to worry if many models use it.

    Define it at the application level inside your main acts_as_something.rb file for instance.

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

Sidebar

Related Questions

I am using Ruby on Rails 3 and I would like to know some
I am using Ruby on Rails v3.0.9 and I would like to know what
I am using ruby 1.8.7 and rails 2.3.4 . I am developing a plugin
We are developing a considerably big application using Ruby on Rails framework (CRM system)
I am using Ruby on Rails with Cucumber and Capybara. How would I go
I am considering developing an application using Ruby on Rails that is a planner
I am developing a ruby on rails website using heroku and git. What tools
I am developing a small Ruby-on-rails application. I am using 'roo' gem to open
I've only just started learning ruby on rails and I would like to create
I am using Ruby on Rails 3 and I am developing API for my

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.