views:

146

answers:

1

I have the following wrapper method for link_to:

def link_to_with_current(text, link, condition, *args)
  current_class = condition ? 'current' : nil
  link_to text, link, :class => current_class, *args
end

When called with this sample:

link_to_with_current 'My Link', '/mylink.html', true, :id => 'mylink'

The following link is generated:

<a href="/mylink" class="current">My Link</a>

Why doesn't the ID show up?

A: 

Thanks to theIV's suggestion, I found a version that works:

def link_to_with_current(text, link, condition, *args)
  options = args.first || {}
  options[:class] = condition ? 'current' : nil
  link_to text, link, options
end
Jimmy Cuadra