Chris Bruce
2006-May-04 23:47 UTC
[Rails] Re: How do I identify the initiating View from within aHelper?
Lindsay, Wouldn''t you want to use a component for this? I know components seem to be out of favor, but they seem like a perfect fit for this very thing. You could then go like: <%= render_component :controller => ''sidebar'', :action => ''home_menu'' %> The :action parameter could even be more dynamic based on your own needs. Maybe someone knows a better way? Chris -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Mark Reginald James Sent: Friday, May 05, 2006 2:20 AM To: rails@lists.rubyonrails.org Subject: [Rails] Re: How do I identify the initiating View from within aHelper? Lindsay Boyd wrote:> I would like to call a helper method from my View to construct asidebar> menu. The menu is contextual, so ideally I would like to do something > like this: > > View > ---- > <%= sidebar_menu %> > > Helper > ------ > def sidebar_menu > case _calling_view_ > when ''_view_identifier_'' > ... build menu... > end > end > > where ''_calling_view_'' is the key that points to the > ''_view_identifier_'', if this this makes sense! > > I could send a parameter with the method call (eg > sidebar_menu(''search_screen'')), but I consider this redundant. > > Is this possile? Is there a better approach?The action name is available as "action_name". As for the view name, all I can see after a quick look through the Rails code is the variable "@first_render". It''ll work, but is undocumented, and so is not guaranteed to work in future versions. -- We develop, watch us RoR, in numbers too big to ignore. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Lindsay Boyd
2006-May-05 00:07 UTC
[Rails] RE: Re: How do I identify the initiating View from within aH
Chris Bruce wrote:> Lindsay, > > Wouldn''t you want to use a component for this? I know components seem > to be out of favor, but they seem like a perfect fit for this very > thing.Thanks for the tip, Chris. I think I need to re-read the Action View section in Agile that covers layouts and components. Lindsay -- Posted via http://www.ruby-forum.com/.