在助手中截断

时间:2013-02-19 15:53:31

标签: ruby-on-rails

我在Rails 3中有以下帮助:

def other_contact_info(shop = false)
  shop = shop ? shop : @shop
  email = mail_to(shop.email, "Email", :encode => "javascript") if shop.web.present?
  web = link_to(shop.web, truncate(shop.web), :target => "_blank") if shop.web.present?
  raw [shop.contact, email, web].select(&:present?).join(" · ")
end

truncate没有做任何事情。我该如何解决这个问题?

感谢。

1 个答案:

答案 0 :(得分:2)

link_to中的第二个参数是URL。我想你想要truncate是第一个参数,它是显示给用户的链接文本:

link_to(truncate(shop.web), __URL__, :target => "_blank")