Forum: Ruby on Rails multiple 'render :partial' in a helper ??

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2006-02-02 12:10
(Received via mailing list)
Hi all,


I'd like to move some view code to a helper but it doesn't work because
I need to render two partials each time.
Q: Is it possible to do this with a helper?

Example:
-----------------

Before: In the view:
   ...
   <% case controller.controller_name
        when 'member' %>
		<%= render :partial => 'shared/member_menu' 	%>
		<%= render :partial => 'shared/member_submenu'  %>
         ..
    <% end %>
    ...



After: In the view:
    <%= generate_menu %>


After: in application_helper.rb (DOESN'T WORK)

def generate_menu
     case controller.controller_name
         when 'member'
              render :partial => 'shared/member_menu'   <--- HAS NO
EFFECT !!
              render :partial => 'shared/member_submenu'
         ...
     end
end

problem: the 1st 'render :partial' has no effect


Alain
82476266af9d460415d8f1fc16bb54ed?d=identicon&s=25 Jarkko Laine (jarkko)
on 2006-02-02 12:34
(Received via mailing list)
Alain,

On 2.2.2006, at 13.07, Alain Ravet wrote:
> EFFECT !!
>              render :partial => 'shared/member_submenu'
>         ...
>     end
> end
>
> problem: the 1st 'render :partial' has no effect

Remember that helpers are methods that return something, so they
can't render directly to the response like you seem to assume above.
By default they will return the last evaluated line, in this case
what your second render line returns.

You can probably concatenate the two to a single return value.

//jarkko
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2006-02-02 14:32
(Received via mailing list)
Jarkko

Of course, you're right. What was I thinking?

       > You can probably concatenate the two to a single return value.

Yes :

def generate_menu
     case controller.controller_name
         when 'member'
              a = render :partial => 'shared/members_avantages_menu'
              b = render :partial => 'shared/member_submenu'
              a+b     <<---- CONCATENATION
          when ..
              ...
     end
end


Thanks again for waking me up.

Alain
This topic is locked and can not be replied to.