views:

82

answers:

2

Rails has the link_to helper, and I'm aware that its output is determined by the ActionView::Helper::UrlHelper` method, but what is an easy and simple way to modify the behavior or rather make a different helper that would work similarly, the default behavior would output something similar to:

<a href="/blah" class="my_link">go to blah</a>

So say I wanted to have a <span> inside the <a> like so:

<a href="/blah" class="my_link"><span>go to blah</span></a>

If I wanted to create the helper, I'm aware that I should probably put in in my app/helpers/application_helper.rb file but how would I construct it?

+1  A: 

link_to takes a block. You can do just about anything you want in there.

Azeem.Butt
Awesome, found it in the docs.
Joseph Silvashy
A: 

Helper is just normal function, there is nothing magic about it:

def my_link_to
  put your code here
end
Adrian Serafin