Passing a variable to a partial

I have a chunk of rhtml that gets reused by several views in several
controllers. I make partial out of it _foo and call it with

<%= render :partial =>‘bar/foo’ %>

RAILS_ROOT/app/views/bar/_foo.rhtml

(note I’m not calling with a collection.) Is there a way to send a
variable to the partial? the doc says i can use :locals => { :name =>
‘val’ } but what I want to do is alias :name to another variable. I
can always set some class variable @var and using that inside the
partial, but I want to make it explicit what it is that I’m passing to
the partial.

also, is this the way to share something among views? I’m aware of
layouts but that seems to be for whole page content, rather than
common snippets.

On Dec 13, 2007, at 7:52 AM, rubynuby wrote:

can always set some class variable @var and using that inside the
partial, but I want to make it explicit what it is that I’m passing to
the partial.

also, is this the way to share something among views? I’m aware of
layouts but that seems to be for whole page content, rather than
common snippets.

Have a look at the methods discussed in this article,
http://www.railsdev.ws/blog/3/modular-page-assembly-in-rails/


def gw
acts_as_n00b
writes_at(www.railsdev.ws)
end

On 13 Dec 2007, at 18:15, Phillip K. wrote:

end

As usual, you’re on the ball Greg. I was thinking about that very
resource, but couldn’t remember where I saw it.

Well it would be surprising if he’d forgotton something he’d written
himself :slight_smile:

Fred

On Dec 13, 2007, at 10:30 AM, Greg W. wrote:

Have a look at the methods discussed in this article,
WEBSITE.WS - Your Internet Address For Life™


def gw
acts_as_n00b
writes_at(www.railsdev.ws)
end

As usual, you’re on the ball Greg. I was thinking about that very
resource, but couldn’t remember where I saw it.

Peace,
Phillip

On Dec 13, 2007, at 12:52 PM, Frederick C. wrote:


Well it would be surprising if he’d forgotton something he’d written
himself :slight_smile:

Fred

Aye, and you are on the ball, too, Fred. :slight_smile:

Peace,
Phillip

thank you. excellent article.

an O/T question. what is the font used in the pdf for the code
portion? it’s a nice fixed monospace font and I’m always on the
lookout for good monospace fonts to use for coding :slight_smile: Currently I use
Lucida Console but it has a problem in that commas and periods look
too much alike.

On Dec 13, 2007, at 10:52 AM, Frederick C. wrote:

himself :slight_smile:
Well, given that I tend to write such things at the moment I reach my
epiphany about the topic, I can very easily forget what I write :slight_smile:
I’ve been pointed to my own advice more than once :stuck_out_tongue:


def gw
acts_as_n00b
writes_at(www.railsdev.ws)
end

On Dec 13, 2007, at 2:13 PM, rubynuby wrote:

an O/T question. what is the font used in the pdf for the code
portion?

That would be Monaco (default monospaced font on a Mac)

– gw