CLEAN and DRY

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…

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 [email protected] wrote:


http://www.jeremymcanally.com/

My books:
Ruby in Practice

My free Ruby e-book

My blogs:

http://www.rubyinpractice.com/

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