开发者

ruby: how to access properties specified in config files inside my models and controllers [closed]

开发者 https://www.devze.com 2023-01-13 19:52 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

As title says, I have a yaml file with values like

development:

email:dev@abc.com

test:

email:test@abce.com

production:

prod@abc.com

and i load this file in an rb file located under "initializers" directory as

SpecFile = YAML.load_file("#{RAILS_ROOT}/config/application.yml")

Question is, I need to access these values in my models and controller files. In html, I refer thme u开发者_StackOverflowsing <%= SpecFile['test']['email']%> which i am not sure is the correct way or not. (I use ror 1.8.7)

Any help is appreciated

Thanks


You can use:

spec_file = SpecFile['test']['email']
  • See my answer here for full details.
0

精彩评论

暂无评论...
验证码 换一张
取 消