Concatenating Two Views

Hello,

I’m a beginner with a question about concatenating some things. The app
I’m trying to work on has the following line for building the right
column in a standard 3 column header/footer layout:

<% @content_for_right = render( :partial => ‘shared/user_profile’,
:object
=> @user) %>

Where user_profile includes a picture of the person and some other
stuff.

I’ve created an additional view file, shared/_advert.rhtml

If we want @content_for_right to now include both user_profile and also
_advert, how would you re-write the above line to show both?

Many thanks,

rob b

ps. I may not be using the ‘view’ terminology correctly.

It looks like you would also be interested in the “content_for” method.
Check out the api or this article on “Err the Blog”:

any file that starts with and underline (_advert.rhtml) is actually a
partial. To display another partial you simply call render(:partial =>
“shared/advert”) again, though you may want to rethink how you’re
printing
it to the overall view. Instead of setting a variable to hold your
render
partial, maybe just print it straight to the view
[view]
<%= render(:partial => “my_partial”) %>
[/view]

otherwise if you absolutely need to concat the two, I believe that
partial
simply returns a string so if you must you should be able to do this:

[view]
<% content_for_right = (render(:partial => “user_profile”) +
render(:partial
=> “advert”)) %>
[/view]

It’s possible to do, but you may want to reconsider your approach the
layout
of your page.

On 11/29/06, Rob Ba [email protected] wrote:

=> @user) %>

rob b

ps. I may not be using the ‘view’ terminology correctly.


Posted via http://www.ruby-forum.com/.


Mike W.
Web D.
UW-Eau Claire