Rahoul Baruah <lists@madeofstone.net> writes:
> On Wednesday, 18 November 2015 09:48:38 UTC, ruud wrote:
>
>
>> Hi Matt,
>> thanks for your advice. Maybe this is an alternative in this case, but I
>> would like to know how to tackle this for custom functions in general.
>> I found out that if I copy the function to config/application, rake finds
>> it. If it is the proper solution for yml-helper functions I don't know.
>> Maybe someone has advice on this.
>>
>>
> Not exactly the same thing but I have a config/storage.yml file for holding
> my S3 configuration - and I load it in config/initializers/storage.rb -
> load the YAML as a text file, use ERB to parse it and then apply the file.
> So any functions I had defined within config/initializers/storage.rb
> should be available to the ERB parser.
>
> contents = File.open(File.join(Rails.root, 'config', 'storage.yml')) { | f
> | f.read }
> contents = ERB.new(contents).result
> yaml = YAML.load(contents)
>
> AqrReports::Application.config.image_options = yaml['images'][Rails.env]
> AqrReports::Application.config.file_options = yaml['files'][Rails.env]
This is for Rahoul, not the OP:
Rails 4.1 introduced the #config_for method on the Rails application,
which makes all the reading, erbing, and yamling of config files really
super simple. You can change your above initializer to:
STORAGE_CONFIG = Rails.application.config_for(:storage)
AqrReports::Application.config.image_options = STORAGE_CONFIG['images']
AqrReports::Application.config.file_options = STORAGE_CONFIG['files']
From the looks of things, you may need to rearrange your storage.yml to
be in the same structure as database.yml.
--
Tamara Temple
tamouse@gmail.com
http://www.tamouse.org
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/m2610zcfja.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment