I think something like this should work
def clever_name_for_link_helper(text, controller, action)
options = (if params[:controller] == controller) ? {:class => :current} :
{}
link_to text, {:controller => controller, :action => action}, options
end
I had a hard time with the name [obviously the one I used isn''t real]
because link_to_current_class implies you''re linking to the
current_class.
Perhaps link_with_current_class or mark_link_if_current_class or something?
RSL
On 3/10/07, Nicholas Wieland
<nicholas.wieland-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> Hi *,
> someone has suggestions on how to improve this code ? For example
I''d
> like my parameteres to be similar to the original link_to
> helper, :controller => :blah, :action => :blah and so on ...
>
> def link_to_current_class(name, controller, action)
> link_to name, :controller => controller, :action => action if
> params[:controller] != controller
> link_to name, { :controller => controller, :action => action },
> { :class => ''current'' }
> end
>
> A better naming is also appreciated :)
>
> ngw
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---