How to extend Rails link_to helper to add a specific class and not to break link_to standard functionality. I want to have my custom helper like this:
module MyModule
module MyHelper
def my_cool_link_to(body, url_options, html_options)
# here add 'myclass' to existing classes in html_options
# ?? html_options[:class] || =
link_to body, url_options, html_options
end
end
end
I want to remain all the functionality of link_to:
=my_cool_link_to 'Link title', product_path(@product)
# <a href=".." class="myclass">Link title</a>
=my_cool_link_to 'Link title', product_path(@product), :class=>'btn'
# <a href=".." class="btn myclass">Link title</a>
=my_cool_link_to 'Link title', product_path(@product), :class=>'btn', 'data-id'=>'123'
# <a href=".." data-id="123" class="btn myclass">Link title</a>
etc.