Render partial only if it exists

Hi,
Currently, my application.rhtml does this:

render :partial => ‘menu’

which renders a different file based on the controller.

Not all views will have this partial so I want the render to only happen
if the template exists. Currently I get an error if the file does not
exist.

How can I check for the presence of the _menu.rhtml file before
rendering?

Something like

render_partial_if_exists :partial => ‘menu’

Thanks.

On 10/1/07, John L. [email protected] wrote:

exist.

How can I check for the presence of the _menu.rhtml file before
rendering?

It might be easier to just catch the error:

<%= render :partial => ‘menu’ rescue nil %>

Just catching the error certainly does the trick. Thanks!

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