我有aws.yml
development:
asset_host: 'abcd1234efgh@cloudfront.net'
我创建了assets.rb
AWS_CONFIG = Rails.application.config_for(:aws)
unless (AWS_CONFIG.nil? || AWS_CONFIG['asset_host'].nil?)
Rails.application.config.asset_host = AWS_CONFIG['asset_host']
end
如果aws.yml
不存在,我正在尝试实现逻辑,那么它应该完全爆炸并阻止rails服务器启动。知道我怎么能实现这个目标?
答案 0 :(得分:0)
您可以根据自己的情况提出错误。
raise "Essential file doesn't exist"
答案 1 :(得分:0)
您应该将此代码放在初始化程序中并检查
AWS_CONFIG = Rails.application.config_for(:aws)
unless (AWS_CONFIG.nil? || AWS_CONFIG['asset_host'].nil?)
raise "AWS file doesn't exist"
end
并检查
unless File.exist? File.expand_path "aws.ics" #proper path of your file
raise "AWS file doesn't exist"
end