Alain Goldman
Alain Goldman

Reputation: 2908

Rails Haml with inline styling

How would I assign inline styling for a backround-image with a object url in haml? lol. This is a working version of the div without the object.

.main-image{style: "background-image: url('http://example.com/image.jpg');"}

But when I try this:

.main-image{style: "background-image: url(= @photos[0].image.url);"}

It doesn't work out when I add @photos[0].image.url, any ideas?

Upvotes: 1

Views: 4548

Answers (2)

Marek Lipka
Marek Lipka

Reputation: 51151

You should interpolate this value, instead of writing it directly in your string:

.main-image{style: "background-image: url(#{@photos[0].image.url});"}

Upvotes: 5

ema
ema

Reputation: 5773

Did you tried with string interpolation:

.main-image{style: "background-image: url(#{@photos[0].image.url});"}

Upvotes: 1

Related Questions