Staying DRY -- can views share partials?

Let’s say I have a “main” controller/view and a “sub” controller/view.
If I have defined a partial in “main” for the site header
(_site_header.rhtml) can I share it with “sub” or does “sub” have to
duplicate it, use a symbolic link to the file, or convert the cool
partial into an ugly helper?

It would be nice to have a shared placed for partials. Similar to
app/helper/application.rb.

I know I could use a helper, but when it comes to views, partials are so
much nicer.

Thanks,
Dale

put the shared partial in app/views/shared/
and reference it with <%= render :partial => ‘shared/partial_name’ %>

hope this helps,

Mike

In your sub view, you can use this to render the partial from main.

render :partial => ‘main/site_header’

Also, you could put the header in a layout and have each controller
use that layout.

mark

On 6/23/06, Dale M. [email protected] wrote:

much nicer.


Mark Van H.
[email protected]
http://lotswholetime.com

I usually create a folder under views called “shared” and then put all
my
shared partials in there. I then reference them from any controller view
with

render :partial => ‘shared/_partial’

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs