Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML title attribute in Rails displaying only first word

Got a weird little problem.

I want to create the text hover on an item to display that item's "description," which is an attribute of that item's model. So I basically did this in my view:

<div title=<%= item.description %> ><%= item.name %></div>

The weird thing is, while all the model calls are working correctly (item.name and item.description are calling up the right things), only the first word of item.description is showing up when I hover. In other words, if item.description is "This is a super cool item!", when I hover over that div with item.name, the hover just says "This".

This may have something to do with the :description attribute, which is currently of type text, (which I thought was for long strings, like my descriptions). But maybe not.

Any idea why this might be happening, and how to fix it?

like image 629
Sasha Avatar asked Oct 23 '25 14:10

Sasha


2 Answers

Insert double qutoes for title in the div tag

<div title="<%= item.description %>" ><%= item.name %></div>
like image 100
AnandVeeramani Avatar answered Oct 26 '25 04:10

AnandVeeramani


I think you need to add quoting to the HTML in the view. If you view source on the generated HTML, I'm willing to bet it looks like this:

<div title=This is a super cool item! >

The browser will interpret that as the div having a title with the value This, and then attributes named is, a, super, cool, and item!.

If you change your view to this:

<div title="<%= item.description %>" >

Then your generated HTML should look like this:

<div title="This is a super cool item!" >
like image 26
dpassage Avatar answered Oct 26 '25 04:10

dpassage



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!