C 레일에 표시되지, 환경 변수가 나는 application.ymlEnvirontment 변수 내가 레일에 루비에 대해 물어 싶어
defaults: &defaults
STORE_URL: https://localhost:3000/
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
이 같은 코드를 가지고 application.yml
를 사용하여 설정할 수 있습니다 또한 application.rb
Bundler.require(*Rails.groups)
if File.exists?(File.expand_path('../application.yml', __FILE__))
config = YAML.load(File.read(File.expand_path('../application.yml', __FILE__)))
config.merge! config.fetch(Rails.env, {})
config.each do |key, value|
ENV[key] ||= value.to_s unless value.kind_of? Hash
end
end
의 구성을 설정하고 .gitignore이 코드를 추가
,config/appication.yml
.project
나 단말기에서 테스트 할 때 출력이 같아야,
[1] pry(main)> ENV
=> {"Test1"=>"Tester1",
"Test2"=>"Tester2",
"Test3"=>"Tester3"}
는 단지 추가해야 몇몇 키와 값 때 레일 3.0.20 루비 1.9 run rails c development
. 3p545 형식으로 테스트하거나 application.yml .but, Rails 4.1.5 및 Ruby 2.0.0p541에 새로운 키 및 값을 추가하면 간단 해집니다.
전체 Application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
if File.exists?(File.expand_path('../application.yml', __FILE__))
config = YAML.load(File.read(File.expand_path('../application.yml', __FILE__)))
config.merge! config.fetch(Rails.env, {})
config.each do |key, value|
ENV[key] ||= value.to_s unless value.kind_of? Hash
end
end
module ModuleUpgrade
class Application < Rails::Application
end
end
도움이 필요하십니까? 감사합니다.
을 application.yml에 설정하고 레일즈 C 및 유형 ENV에서 테스트 할 때 표시됩니다. @spickermann – agstwn21
미안하지만 당신이하고 싶은 말을 이해하지 못합니다. – spickermann
네 .. 나도 레일에 루비가있어. 그래서 나는 단지 무슨 뜻인지 짐작한다. @spickermann – agstwn21