Forum: Ruby on Rails How do I identify the initiating View from within 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.
Ae03102311939454d2b7f1ca3139fd97?d=identicon&s=25 Lindsay Boyd (Guest)
on 2006-05-04 12:45
I would like to call a helper method from my View to construct a sidebar
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?

-Lindsay
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2006-05-05 01:25
(Received via mailing list)
Lindsay Boyd wrote:
> def sidebar_menu
> 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.
This topic is locked and can not be replied to.