How do I define application-specific settings in Ruby on Rails?

Asked 2 years ago, Updated 2 years ago, 57 views

How should I define application-specific configuration information?

I got an error when I created my_config.yml under /config and my_config.rb under /config/initializers.The contents of each file are as follows:

my_config.yml:

COMMON:&COMMON
 author: "user name"
 logo:
  source: "http://www.wings.msn.to/image/wings.jpg"
  width:215
  height —67

development:
  hoge: "dev"
  <<:*COMMON

test:
  hoge: "test"
  <<:*COMMON

production:
  hoge: "pro"
  <<:*COMMON

my_config.rb:

MY_APP=YAML.load(File.read("/Users/****/rails_projects/third_app/config/my_config.yml")[Rails.env]
# ****** is the username

ruby-on-rails ruby

2022-09-30 20:51

2 Answers

The program in question should work without any problems, but what kind of errors are occurring?
Some Gems manage environment-dependent values, such as Figaro or dotenv.


2022-09-30 20:51

RailsConfig allows you to read and use configuration information from a YAML file.The configuration can also be set separately for each RAILS_ENV (development, production, test, ...).

There is Settingslogic in a similar gem, but it hasn't been updated for about a year, so you might want to avoid it.


2022-09-30 20:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.