# Plugin and YAML configuration file

**URL:** <https://www.ruby-forum.com/t/plugin-and-yaml-configuration-file/173777>\
**Category:** Rails\
**Created:** [August 14, 2009, 4:07pm UTC](https://www.ruby-forum.com/t/plugin-and-yaml-configuration-file/173777 "2009-08-14T16:07:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [August 14, 2009, 4:07pm UTC](https://www.ruby-forum.com/t/plugin-and-yaml-configuration-file/173777/1 "2009-08-14T16:07:16Z")

</div>

Hello,

Using an external YAML file for storing static datas is cool. And doing  
so in a basic Rails application is easy using in  
config/initializers/load\_config.rb such:  
CONFIG = YAML.load\_file("#{RAILS\_ROOT}/config/config.yml")  
…after what datas can be called in application.rb with  
CONFIG[‘something’].

But how can we load the YAML configuration file of a plugin (in its  
controller for instance)? For example if my plugin is in  
vendor/plugins/my\_plugin and its YAML file is in  
vendor/plugins/my\_plugin/config.yml?

And I have an other question about this topic: is that possible to  
complet the Rails internationalization’s YAML files stored in  
config/locales/ using a additionnal YAML file into the plugin (in order  
to generate dynamic flash messages for instance in plugin’s controllers,  
like so: flash[:error] = t(there\_is\_an\_error))?

Many thanks for any answers.

D.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [August 15, 2009, 1:03am UTC](https://www.ruby-forum.com/t/plugin-and-yaml-configuration-file/173777/2 "2009-08-15T01:03:38Z")

</div>

On Aug 14, 3:07 pm, “David B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> controller for instance)? For example if my plugin is in  
> vendor/plugins/my\_plugin and its YAML file is in  
> vendor/plugins/my\_plugin/config.yml?

Well you can have your plugin’s code do anything you want, including  
read in such a yaml file if you want.

> And I have an other question about this topic: is that possible to

> complet the Rails internationalization’s YAML files stored in  
> config/locales/ using a additionnal YAML file into the plugin (in order  
> to generate dynamic flash messages for instance in plugin’s controllers,  
> like so: flash[:error] = t(there\_is\_an\_error))?

You could try adding the appropriate folder(s) to the i18n load path.

Fred

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [August 15, 2009, 10:09am UTC](https://www.ruby-forum.com/t/plugin-and-yaml-configuration-file/173777/3 "2009-08-15T10:09:58Z")

</div>

Thank you for your answer, Frederick.

Is there an example of plugin using those mechanisms?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [August 15, 2009, 11:08am UTC](https://www.ruby-forum.com/t/plugin-and-yaml-configuration-file/173777/4 "2009-08-15T11:08:47Z")

</div>

On Aug 15, 9:09 am, “David B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Thank you for your answer, Frederick.
> 
> Is there an example of plugin using those mechanisms?

Not that I’ve seen, but then I haven’t looked. The rails I18n guide  
probably discusses the i18n load path stuff and the configuration  
stuff should be straight forward - loading some yaml and assigning it  
to a constant isn’t going to be radically different just because a  
plugin is involved.

Fred
