Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Truncate with an on hover function

Hi there guys trying to gather some ideas to tackle this problem. i am using rails to truncate a name of a company that`s over 30 characters in length. the page will load the name of the company into the header of the page if the name is too long it will cut some other stuff off and messes with the styling. to truncate i have this server side.

truncate(company.title, :ommision => "...", :length => 20)

is it possible to maybe do something in jQuery. so that if i hover the mouse over the truncated text the name will hover just above. or if you know of a better way anything would be cool.

like image 726
TheLegend Avatar asked Mar 06 '12 07:03

TheLegend


1 Answers

I would propose doing something like this.

Create a helper with something like this. The truncate method used to take just a length parameter, but this has changed and it now takes a hash of parameters.

def truncate_with_hover(text_to_truncate, length = 30)
    "<span title='#{text_to_truncate.gsub("'","\\'")}'>#{truncate(text_to_truncate, :length => length)}</span>" if !text_to_truncate.blank?
end
like image 65
HannesBenson Avatar answered Sep 22 '22 01:09

HannesBenson