# Application-wide layouts?

**URL:** <https://www.ruby-forum.com/t/application-wide-layouts/103732>\
**Category:** Engines Development\
**Created:** [May 9, 2007, 7:53pm UTC](https://www.ruby-forum.com/t/application-wide-layouts/103732 "2007-05-09T19:53:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![coldtone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@coldtone](https://www.ruby-forum.com/u/coldtone)\
**Post date:** [May 9, 2007, 7:53pm UTC](https://www.ruby-forum.com/t/application-wide-layouts/103732/1 "2007-05-09T19:53:07Z")

</div>

Hey all. I’m making use of Engines-based plugins in several of my  
sites. I have a wiki, a login engine, a CRM tool… Right now, I  
install the plugin(s), then have to create a mask controller containing  
a layout “standard-layout” call, and that’s it. This would seem to be a  
common problem for any engine-type plugin that aims to integrate with  
(rather than live separately from) the main app.

Is there a better solution that I’m not seeing with existing code?

Assuming there isn’t (I’ve looked), what would people think about  
patching in support to the layout system of Rails to support an  
application-wide default layout? The Rails docs mention using  
“application.rhtml” as a way to achieve this, but it doesn’t work, and  
there’s no code in place to support it in the latest stable release that  
I can find.

Thoughts?

---

<div class="post-metadata">

**Author:** ![coldtone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@coldtone](https://www.ruby-forum.com/u/coldtone)\
**Post date:** [May 9, 2007, 8:03pm UTC](https://www.ruby-forum.com/t/application-wide-layouts/103732/2 "2007-05-09T20:03:09Z")

</div>

Simply creating an application.rhtml file inside of your base  
application’s app/views/layouts directory should certainly do the  
trick. When doing that you don’t need to specify a ‘layout’ directive  
in your controllers since that’s the default. I’m doing this  
currently in my application and it too uses engine plugins. No  
problems.

Cheers,  
Aaron

On 5/9/07, Rob M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Assuming there isn’t (I’ve looked), what would people think about patching  
> [http://lists.rails-engines.org/listinfo.cgi/engine-developers-rails-engines.org](http://lists.rails-engines.org/listinfo.cgi/engine-developers-rails-engines.org)

–  
Aaron Campos  
removed\_email\_address@domain.invalid  
skype & AOL IM: aaroncampos

---

<div class="post-metadata">

**Author:** ![coldtone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@coldtone](https://www.ruby-forum.com/u/coldtone)\
**Post date:** [May 9, 2007, 8:14pm UTC](https://www.ruby-forum.com/t/application-wide-layouts/103732/3 "2007-05-09T20:14:34Z")

</div>

Aaron, what version of Rails are you running? I’m using 1.2.3 and  
adding an application.rhtml doesn’t have any effect. I looked through  
the render() and layout code in the codebase, looking for an  
application.\* default, and couldn’t find it. Is it possible you’re  
running an older version of Rails, and that the current rev has dropped  
that feature, for some reason?

-Rob

---

<div class="post-metadata">

**Author:** ![coldtone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@coldtone](https://www.ruby-forum.com/u/coldtone)\
**Post date:** [May 17, 2007, 6:04pm UTC](https://www.ruby-forum.com/t/application-wide-layouts/103732/4 "2007-05-17T18:04:03Z")

</div>

On 5/9/07, Rob M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Aaron, what version of Rails are you running? I’m using 1.2.3 and adding  
> an application.rhtml doesn’t have any effect. I looked through the render()  
> and layout code in the codebase, looking for an application.\* default, and  
> couldn’t find it. Is it possible you’re running an older version of Rails,  
> and that the current rev has dropped that feature, for some reason?

Hi Rob,

Sorry for the delayed response. Nope, I’m using Rails 1.2.3. Perhaps  
reading through the layout section in the API doc will help:

[http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html#M000129](http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html#M000129)

HTH,  
Aaron

–  
Aaron Campos  
removed\_email\_address@domain.invalid  
skype & AOL IM: aaroncampos

– Find me at RailsConf –

---

<div class="post-metadata">

**Author:** ![coldtone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@coldtone](https://www.ruby-forum.com/u/coldtone)\
**Post date:** [July 28, 2007, 3:13pm UTC](https://www.ruby-forum.com/t/application-wide-layouts/103732/5 "2007-07-28T15:13:15Z")

</div>

On 7/27/07, Rob M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> How do I figure out, safely and consistently, that a given plugin
> 
> ```
> 
> has been installed? I seem to recall some sort of list being maintained  
> by Rails, but couldn’t find where I read about it. Is there such a  
> list? When does it get initialized?

The engines plugin, for Rails 1.2, created an array of all the loaded  
plugins, accessible via “Rails.plugins”. This is a list of every  
plugin that was loaded (and reflects the order they were loaded too).  
This list is set up as soon as the engines plugin loads, and is then  
built by the Rails::Initializer extensions that the engines plugin  
provides.

Rails.plugins is actually a PluginList, which means that you can do

Rails.plugins.first  
Rails.plugins[0]  
Rails.plugins[:plugin\_name]  
Rails.plugins[“plugin\_name”]

… and they all will return the plugin at the given index, or with  
the given name.

> Second question:
> 
> ```
> I'm planning on creating the relationships using polymorphic
> 
> ```
> 
> associations. Is there a smarter/better way to do this? Has anyone  
> tried cross-plugin associations?

You should be able to do this, as long as Plugin A doesn’t need to  
actually load or instantiate any of the models from Plugins B before  
Plugin B has loaded. Any kind of inter-plugin-dependency will need  
careful management to ensure that code isn’t eagerly loaded while the  
plugins are loading.

HTH,

James

---

<div class="post-metadata">

**Author:** ![coldtone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@coldtone](https://www.ruby-forum.com/u/coldtone)\
**Post date:** [July 27, 2007, 3:40am UTC](https://www.ruby-forum.com/t/application-wide-layouts/103732/6 "2007-07-27T03:40:58Z")

</div>

Hey smart people. I’m trying to solve a problem I am sure has been  
solved by someone out there already, and am hoping one of them is on  
this list.

Here goes, as simply as I can make it:

I am building a set of engine-ized plugins for core services I want to  
reuse (like C++ libraries). So, for example, I have a calendar plugin,  
a user management plugin, a file management plugin…

I want to have relationships between these plugins, for example, have a  
User optionally has\_one() a Calendar. This should _only_ happen if the  
calendar plugin is installed.

So, first question:

```
How do I figure out, safely and consistently, that a given plugin

```

has been installed? I seem to recall some sort of list being maintained  
by Rails, but couldn’t find where I read about it. Is there such a  
list? When does it get initialized?

Second question:

```
I'm planning on creating the relationships using polymorphic

```

associations. Is there a smarter/better way to do this? Has anyone  
tried cross-plugin associations?

Thanks for any thoughts/advice on this. I’m _really_ enjoying the  
functionality the engines plugin provides. (Thanks, James!)

-Rob M.
