Forum: Ruby on Rails Playing with link_to helper

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bd0ecd69dba2aab1a0261ee46e090139?d=identicon&s=25 Nicholas Wieland (Guest)
on 2007-03-10 14:55
(Received via mailing list)
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' }

A better naming is also appreciated :)

70225136eacd3d870f64e03bff678655?d=identicon&s=25 Russell Norris (Guest)
on 2007-03-11 16:07
(Received via mailing list)
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

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
Perhaps link_with_current_class or mark_link_if_current_class or

This topic is locked and can not be replied to.