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
Alain, On 2.2.2006, at 13.07, Alain Ravet wrote:> 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 effectRemember 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 -- Jarkko Laine http://jlaine.net http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2363 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060202/4af40989/smime.bin
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