# CLEAN and DRY

**URL:** <https://www.ruby-forum.com/t/clean-and-dry/125198>\
**Category:** Rails\
**Created:** [January 6, 2008, 11:38pm UTC](https://www.ruby-forum.com/t/clean-and-dry/125198 "2008-01-06T23:38:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spokra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@spokra](https://www.ruby-forum.com/u/spokra)\
**Post date:** [January 6, 2008, 11:38pm UTC](https://www.ruby-forum.com/t/clean-and-dry/125198/1 "2008-01-06T23:38:27Z")

</div>

is it possible to include a partial from within the global  
application.html.erb?

I have a google ad in my application.html.erb I would like to move  
it to a partial \_google.html.erb in my layouts directory to keep  
things CLEAN… but i guess ERB is only looking in the current views  
directory not the layouts dir… would not make sense to move it to a  
partial and then duplicate the \_google.html.erb in all views, thats  
not very DRY…

---

<div class="post-metadata">

**Author:** ![spokra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@spokra](https://www.ruby-forum.com/u/spokra)\
**Post date:** [January 6, 2008, 11:55pm UTC](https://www.ruby-forum.com/t/clean-and-dry/125198/2 "2008-01-06T23:55:26Z")

</div>

You can do something like this:

render :partial =\> ‘your\_directory/view\_name’

So if you wanted to put \_google.html.erb in the app/views/shared  
directory, you would do:

render :partial =\> ‘shared/google’

–Jeremy

On Jan 6, 2008 5:37 PM, spokra [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> >

–  
[http://www.jeremymcanally.com/](http://www.jeremymcanally.com/)

My books:  
Ruby in Practice

> **[Ruby in Practice](https://www.manning.com/books/ruby-in-practice)**
>
> Like Ruby itself, Ruby in Practice will make you more productive. The book shows you practical techniques and strategies for small projects and large-scale environments. A cookbook-style reference, it gives you concrete examples of systems...

My free Ruby e-book

> **[Site not found · DreamHost](http://www.humblelittlerubybook.com/)**
>
> The owner of this domain has not yet uploaded their website.

My blogs:

> **[Site not found · DreamHost](http://www.mrneighborly.com/)**
>
> The owner of this domain has not yet uploaded their website.

[http://www.rubyinpractice.com/](http://www.rubyinpractice.com/)

---

<div class="post-metadata">

**Author:** ![spokra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@spokra](https://www.ruby-forum.com/u/spokra)\
**Post date:** [January 6, 2008, 11:57pm UTC](https://www.ruby-forum.com/t/clean-and-dry/125198/3 "2008-01-06T23:57:11Z")

</div>

On Sun, Jan 06, 2008 at 02:37:27PM -0800, spokra wrote:

> is it possible to include a partial from within the global  
> application.html.erb?
> 
> I have a google ad in my application.html.erb I would like to move  
> it to a partial \_google.html.erb in my layouts directory to keep  
> things CLEAN… but i guess ERB is only looking in the current views  
> directory not the layouts dir… would not make sense to move it to a  
> partial and then duplicate the \_google.html.erb in all views, thats  
> not very DRY…

I often create a shared directory in app/views for such things. In your  
case, you’d have app/shared/\_google.html.erb and refer to it as:

\<%= render :partial =\> ‘/shared/google’ %\>

–Greg
