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

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


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

hope this helps,


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.


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

much nicer.

Mark Van H.
[email protected]

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

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