Render partials in helper

hee people,

Is it possible to render partials in helpers ?

Why I want this:
I have a menu that list many links but some of those items are children
of other items.
so i want to have different partials .

Of course I could set the ruby code in my view but that is not cool (I
think :P)

I hope someone nows if this is possible

jeljer te wies

On Aug 11, 2:47 am, jeljer te Wies [email protected]
wrote:

hee people,

Is it possible to render partials in helpers ?

Yup, that’s fine. Is there a reason you thought it wouldn’t be
possible?

Fred

On 11 Aug 2008, at 12:42, jeljer te Wies wrote:

That’s syntactically incorrect - it should be
render :partial => ‘menu/test’

If that’s not the problem then you’re going to have to be a little
more explicit than ‘it didn’t work’

Fred

well I tryed to have a helper method like this:

def test
render :partial ‘menu/test’
end

this didn’t work

Frederick C. wrote:

On 11 Aug 2008, at 12:42, jeljer te Wies wrote:

That’s syntactically incorrect - it should be
render :partial => ‘menu/test’

If that’s not the problem then you’re going to have to be a little
more explicit than ‘it didn’t work’

Fred

OOh I am sorry … I wasn’t clear.

what i have now is this:

def set_menu
render :partial => ‘menu/menu_item’
render :partial => ‘menu/menu_item’
end

I want to render more partials in one helper method. But it renders only
one partial !..
so my real question is .

is it possible to render multiple partials in one helper method

On Aug 11, 1:30 pm, jeljer te Wies [email protected]
wrote:

Frederick C. wrote:

On 11 Aug 2008, at 12:42, jeljer te Wies wrote:

what i have now is this:

def set_menu
render :partial => ‘menu/menu_item’
render :partial => ‘menu/menu_item’
end

The problem here is that you might not quite understandr what happens
when you do <%= some_helper%>
Erb basically calls that method, calls to_s on the result and sticks
it into the document, so the key thing here is getting your set_menu
helper to return the right thing
When you call render :partial => ‘…’ a string is returned containing
the appropriate data. In ruby the value returned by a function is
whatever the last statement evaluated, ie the second call to render.
If you want to return the concatenation of those two things then you
need to stick them together yourself, eg

def set_menu
render( :partial => ‘menu/menu_item’) +
render( :partial => ‘menu/menu_item’)
end

Fred

PS: if that was your original question, saying so from the start would
have saved time for everyone involved.

yes you are right…
But at first I thought that the problem was that it wasn’t possible to
render partials at al.
(and I couldn’t find the answer on google)

thanxs ! allot …
and I hope to answer questions on this forum as soon as I have a better
understanding of ruby and rails.