A
A
Alexander Grishin2015-10-28 12:50:21
Ruby on Rails
Alexander Grishin, 2015-10-28 12:50:21

I can't understand the logic. How to do it right?

<ul class="rating">
            <% 1.upto(5) do |count| %>
              <li class=<%= if product.rate == count then 'star selected' else 'star' end %> >&star;</li>
            <% end %>
          </ul>

I think it will be like this:
<ul class="rating">
<li class="star">☆</li>
<li class="star">☆</li>
<li class="star selected">☆</li>
<li class="star">☆</li>
<li class="star">☆</li>
</ul>

And it's like this for me:
<ul class="rating">
<li class="star">☆</li>
<li class="star">☆</li>
<li class="star">☆</li>
<li class="star" selected="">☆</li>
<li class="star">☆</li>
</ul>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima, 2015-10-28
@beerdy

And it is possible like this:

<li class="star<%= ' selected' if product.rate == count %>" >&star;</li>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question