F6eddf2f983d23c2d031e407852625e9

Tammer Saleh, creator/maintainer of the awesome shoulda plugin posted this to his blog (http://blog.tammersaleh.com/articles/2007/07/26/its-the-little-things). It's an awesome start, but I can see a lot of ways it could be improved, and become truly awesome. What are your takes?

1
2
3
4
5
6
def link(item, msg = nil)
  msg ||= item.send([:name, :title, :id].detect {|n| item.respond_to? n})
  method = "#{item.class.name.underscore}_path"
  parents = item.parents rescue []
  link_to(msg, self.send(method, *parents, item))
end

Refactorings

No refactoring yet !

Bfec5f7d1a4aaafc5a2451be8c42d26a

macournoyer

September 20, 2007, September 20, 2007 08:28, permalink

No rating. Login to rate!

In edge Rails there's polymorphic URLs : http://dev.rubyonrails.org/ticket/6432

1
2
# With polymorphic URLs you could do
url_for(items.parents + [item])

Your refactoring





Format Copy from initial code

or Cancel