custom link_to - ruby on rails

584 Views Asked by At

I have a class Thingy, whose objects often need to create links to other websites. So far the only approach working for me is the following:

class Thingy < Active:Record::Base
  def makeLink
    result = "<a href=\"someURL"+self.firstProperty+"\">"+self.secondProperty+"</a>"
  end
...

Now in any view I could use this link-method as follows

thingy.makeLink.html_safe

Somehow I feel there should be a much better way. What is the right approach here?

1

There are 1 best solutions below

1
On BEST ANSWER

the proper approach would be to add a ThingyHelper in app/helpers

def behavior_describing_method_name(thingy)
  link_to thingy.secondProperty, "someUrl#{thingy.firstProperty}"
end