views:

20

answers:

1

Hello, I'm building a header partial for a view. I call the partial as following:

<%= render :partial =>"project/header", :locals => {:right_header => 'BLAH BLAH'} %>

The header has a default right_header, but I'd like the option to overwrite it:

<div id="header">
<span class="right">
 Standard Header here
</span>
</div>

The deal is when calling the partial, right_header won't always be defined, I'd like for it to be optional, but that's where I'm struggling and rails keeps erroring... In the partial I've been trying:

<% if right_header.empty? %>
 default header....
<% else %>
 <%= right_header %>
<% end %>

Suggestions? Am I passing this correctly to the partial with locals?

Thank you

+1  A: 

use

if defined? right_header

another way is

right_header ||= 'default'

in the view. so if right_header is not passed in, its value will be default. You can pass in any value too, and later on just do things according to the value of right_header.

動靜能量
Thanks! is the locals a good way to pass an html block to a partial?
TheExit
SHOOT... It's rendering the HTML tag I'm passing as: <a href="">
TheExit
Looks for `html_safe!`
Swanand