legendary_rob
legendary_rob

Reputation: 13002

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.

Upvotes: 5

Views: 894

Answers (1)

HannesBenson
HannesBenson

Reputation: 842

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

Upvotes: 7

Related Questions