# Configuration/Initialization question

**URL:** <https://www.ruby-forum.com/t/configuration-initialization-question/112911>\
**Category:** Engines\
**Created:** [August 24, 2007, 11:53am UTC](https://www.ruby-forum.com/t/configuration-initialization-question/112911 "2007-08-24T11:53:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bart\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bart\_D](https://www.ruby-forum.com/u/Bart_D)\
**Post date:** [August 24, 2007, 11:53am UTC](https://www.ruby-forum.com/t/configuration-initialization-question/112911/1 "2007-08-24T11:53:21Z")

</div>

Hi,

Maybe I’m overseeing something, what is the right place to put  
Engines. (eg public paths) so that it is correctly used  
? (or more generally MyPlugin.config; so that init.rb of my plugin  
behaves differently on startup if I’m running in dev mode or prod mode )

If I put in environment.rb before the initializer it says Engines  
constant is missing (because plugins are not loaded yet)

If I put it after the initializer block it’s too late …

regards,

## Bart

NEW on aXs GUARD: SSL VPN !! (contact your reseller for more info)

* * *

## aXs GUARD has completed security and anti-virus checks on this e-mail ([http://www.axsguard.com](http://www.axsguard.com))

Able NV: ond.nr 0457.938.087  
RPR Mechelen

---

<div class="post-metadata">

**Author:** ![Bart\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bart\_D](https://www.ruby-forum.com/u/Bart_D)\
**Post date:** [August 24, 2007, 11:56am UTC](https://www.ruby-forum.com/t/configuration-initialization-question/112911/2 "2007-08-24T11:56:21Z")

</div>

I believe you’ll want to put it in the config.after\_initialize block,  
somehow.

---

<div class="post-metadata">

**Author:** ![Bart\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bart\_D](https://www.ruby-forum.com/u/Bart_D)\
**Post date:** [August 27, 2007, 10:42am UTC](https://www.ruby-forum.com/t/configuration-initialization-question/112911/3 "2007-08-27T10:42:09Z")

</div>

James A. wrote:

> I believe you’ll want to put it in the config.after\_initialize block, somehow.

That doesn’t seem to do the trick; the engine plugin is loaded and  
init’ed before after\_initialize. So the files are copied to the  
public\_directory specified in the Engines module itself and not to my  
specified directory setting.

regards,

Bart

---

<div class="post-metadata">

**Author:** ![Bart\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bart\_D](https://www.ruby-forum.com/u/Bart_D)\
**Post date:** [August 27, 2007, 1:01pm UTC](https://www.ruby-forum.com/t/configuration-initialization-question/112911/4 "2007-08-27T13:01:51Z")

</div>

Ah,

Sorry - I think I misunderstood what you were trying to achieve. In  
general, there’s no simple way to set the options for a plugin before  
it has loaded. If you need a plugin to have some options set and  
_then_ do something, init.rb probably isn’t the place to achieve this.  
Instead, I’d develop your plugin such that things can happen at the  
end of environment.rb:

MyPlugin.option\_one = :something  
MyPlugin.option\_two = [1,2,3,4]  
MyPlugin.ok\_now\_get\_ready()

It sounds like you’re trying to do something with the public asset  
copying facilities; in this case, you _should_ be able to re-set the  
Engines.public\_directory parameter at the bottom of environment.rb  
file, and then call  
Rails.plugins[:your\_plugin\_name].mirror\_plugin\_assets. That might do  
what you hope.

What is it that you’re specifically trying to do?

---

<div class="post-metadata">

**Author:** ![Bart\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bart\_D](https://www.ruby-forum.com/u/Bart_D)\
**Post date:** [August 27, 2007, 1:42pm UTC](https://www.ruby-forum.com/t/configuration-initialization-question/112911/5 "2007-08-27T13:42:56Z")

</div>

James A. wrote:

> MyPlugin.option\_two = [1,2,3,4]  
> MyPlugin.ok\_now\_get\_ready()
> 
> It sounds like you’re trying to do something with the public asset  
> copying facilities; in this case, you _should_ be able to re-set the  
> Engines.public\_directory parameter at the bottom of environment.rb  
> file, and then call  
> Rails.plugins[:your\_plugin\_name].mirror\_plugin\_assets. That might do  
> what you hope.

ok, this makes sense. By studying the initializer code I already came to  
the same conclusion but maybe I was overlooking some meta-added  
functionality.  
Or we need to modify the configuration class to add plugin specific  
options or do it like you say above.  
To be honest I was just using the public\_path example as a ‘placeholder’  
for my questions, what I’m really trying to do is explained below.

> What is it that you’re specifically trying to do?

Well I added an option to the engines plugin to symlink the public files  
instead of copy them. So I added Engines.symlink\_asset\_files boolean to  
the module and used it in the  
Engines.mirror\_files\_from.  
In development mode I want to symlink (because some of the plugins I’m  
developing contain assets that get modified during the development  
process of the main application), in production mode I want to copy  
that’s why I wanted to change the setting in config/environment.  
Maybe there is another way of achieving what I want; basically I want to  
have full flexibility in development mode with as least restarting as  
possible. Is it possible to execute mirror\_plugin\_assets before every  
request get’s handled in development mode ?

Oh and BTW thanks for the great engines +plugin+ you made.

regards

bart

---

<div class="post-metadata">

**Author:** ![Bart\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bart\_D](https://www.ruby-forum.com/u/Bart_D)\
**Post date:** [August 27, 2007, 1:47pm UTC](https://www.ruby-forum.com/t/configuration-initialization-question/112911/6 "2007-08-27T13:47:57Z")

</div>

On Mon, Aug 27, 2007 at 01:39:35PM +0200, Bart D. wrote:

> possible. Is it possible to execute mirror\_plugin\_assets before every  
> request get’s handled in development mode ?

This sounds rather overcomplicated to me. I use symlinks too, and this  
works  
fine even without making any configuration changes. Maybe I’m  
misunderstanding  
what you’re trying to do, but I’ll explain how I do it:

If I have a project called ‘myproject’, in my plugin\_assets directory I  
create a symlink by that name to the assets directory in the plugin:  
$ cd public/plugin\_assets  
$ ln …/…/vendor/plugins/myproject/assets myproject

There’s no need to do anything more than this, afaik.

Regards,  
Peter B.  
Solide ICT - [http://www.solide-ict.nl](http://www.solide-ict.nl)

---

<div class="post-metadata">

**Author:** ![Bart\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bart\_D](https://www.ruby-forum.com/u/Bart_D)\
**Post date:** [August 27, 2007, 2:00pm UTC](https://www.ruby-forum.com/t/configuration-initialization-question/112911/7 "2007-08-27T14:00:01Z")

</div>

Peter B. wrote:

> > Maybe there is another way of achieving what I want; basically I want to  
> > create a symlink by that name to the assets directory in the plugin:  
> > $ cd public/plugin\_assets  
> > $ ln …/…/vendor/plugins/myproject/assets myproject
> 
> There’s no need to do anything more than this, afaik.

:-[  
You’re right; shame on me; things can really be simple sometimes …

thx

Bart

---

<div class="post-metadata">

**Author:** ![Bart\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bart\_D](https://www.ruby-forum.com/u/Bart_D)\
**Post date:** [August 27, 2007, 2:04pm UTC](https://www.ruby-forum.com/t/configuration-initialization-question/112911/8 "2007-08-27T14:04:03Z")

</div>

On 8/27/07, Bart D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You’re right; shame on me; things can really be simple sometimes …

The other simple approach would be to attach some behaviour to the  
dispatcher which calls mirror\_public\_files before every request - see  
the “to\_prepare” method in the rails’ Dispatcher for more details 🙂
