开发者

Change block of code based on external config file?

开发者 https://www.devze.com 2023-03-25 11:51 出处:网络
In PHP, i would have a config file that says something like $account = \'on\' and then 开发者_开发技巧throughout my project, i would have if else based on whether that variable equaled on or off.

In PHP, i would have a config file that says something like $account = 'on' and then 开发者_开发技巧throughout my project, i would have if else based on whether that variable equaled on or off.

Now im trying to do something similar in RoR. However, i am pretty new to RoR and considering all the features and implementations rails have, im thinking there has to be a method to basically take a block of code, wrap it in something that says if on, display, if not, dont.

Any suggestions?


# Put this in an initializer
@config = YAML::Load(open([Rails.root, "config/options.yml"].join("/")))

if @config[:account] == "on"
   # do this...
else
   # do this...
end


Take a look at nifty-generators(config generator) or configatron and chose one which better fits your needs and looks more elegant to you.

0

精彩评论

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