0

I'm looking for a way to truncate links displayed in my text.

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>

I want obviously to keep my href working.

Do you have any advice for me? I guess I need to create an helper.

EDIT:

The text ins't static in my views, I want to manage content posted by users in messages, so I have to find a way to truncate links automaticaly

thx

Fabien
  • 273
  • 5
  • 12
  • 1
    Rails has a truncate helper method: http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-truncate – Brian Mar 18 '14 at 19:35

1 Answers1

1

You can use the truncate helper:

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

You can specify the number of characters and the omission (...), for example.

Edit

You need to combine what is suggested on this answers and the truncate method.

Community
  • 1
  • 1
backpackerhh
  • 2,333
  • 1
  • 18
  • 21