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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:48:04+00:00 2026-06-01T19:48:04+00:00

Following the answer on How to define custom configuration variables in rails , I

  • 0

Following the answer on How to define custom configuration variables in rails, I am trying to set up a configuration settings for different environments in config/environments/{env}.rb

e.g. in development.rb I set


config.elvis = 'alive'

and then in my haml template I can use this variable, e.g.

Elvis is #{Rails.configuration.elvis}.

However, when I want to wrap this in a condition:

- if Rails.configuration.elvis
  <p>Elvis is #{Rails.configuration.elvis}</p>

it also works, but if the configuration isn’t set, it throws a undefined method error.

If I try instead:

- if defined? Rails.configuration.elvis
  <p>Elvis is #{Rails.configuration.elvis}</p>

it seems to always evaluate as false, even with the configuration defined.

Still very new to rails/ruby, so apologies if it’s a very dumb question

  • 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-01T19:48:06+00:00Added an answer on June 1, 2026 at 7:48 pm

    You could use respond_to?:

    - if Rails.configuration.respond_to?(:elvis)
      <p>Elvis is #{Rails.configuration.elvis}</p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to answer the following question out of personal interest: What is the
I have the following script taken from another Stack Overflow answer. <?php define('SAVE_FEED_LOCATION','google_base_feed.txt'); set_time_limit(1800);
I found the following answer to that question: A service opens before you even
I tried following the answer to this question , but could not get xsd.exe
I am following the accepted answer of ASP.NET MVC How to pass JSON object
Alex's answer has the following line when translated to English print %2d. %8.2f %8.2f
SOLVED in the last answer im getting following error, dunno where and why? cause
In my answer from yesterday I called the following piece of code a hack:
[Edit] I've summarized the answer to the following below, the error lies in the
In this answer to this question , Lachlan-Hunt writes the following: With HTML5, you

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.