1

I have a need to change the max-width CSS property dynamically depending on how many images there are associated with a given model.

How can I do this w/in Rails 3.1?

(Javascript & SASS/SCSS also at our disposal)

Meltemi
  • 37,979
  • 50
  • 195
  • 293

1 Answers1

5

I suppose you can do this?

<div style="max-width:<%= @somemodel.images.size * X %>px"> ... </div>

Where X is a single image's width.

Alternatively, you can do

<div class="images count<%= @somemodel.images.size %>px"> ... </div>

And then have CSS rules for div.images.count1, div.images.count2, div.images.count3 etc.. but that's not very scalable, so better stick with a style attribute

Flambino
  • 18,507
  • 2
  • 39
  • 58