Change block of code based on external config file?
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.
精彩评论