2014-03-18 56 views
0

我正在尋找一種截斷顯示在我的文本中的鏈接的方法。在Rails中查找和截斷文本中的鏈接

Ie: <p><I want to share a link : http://www.itabc.org/wp-content/uploads/2013/10/Tools-for-Ruby-on-Rails-logo.jpg it rocks!</p> 

Into : <p>I want to share a link : http://www.itabc.org/wp-con... it rocks!</p> 

我想明顯地保持我的href工作。

對我有什麼建議嗎?我想我需要創建一個幫手。

編輯:

文本ins't在我的意見靜態的,我要管理的所發佈消息的用戶的內容,所以我必須找到一個方法來截斷鏈接automaticaly

THX

+1

Rails有截斷helper方法:http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-truncate – Brian

回答

1

您可以使用truncate幫手:

= link_to truncate(text, length: 20), path 

您可以指定的字符數和遺漏(...),例如。

編輯

您需要結合什麼建議在this answerstruncate方法。

+0

我已經詳細說明了我的問題,謝謝@backpackerhh – Fabien

+0

我已經更新了我的回答一些指導。我希望這有幫助。 – backpackerhh