Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby on rails descending loop increments

How do I descent from 5 to 1 instead of going from 1 to 5? I have this...

<div class="field-container rating">
  <% (5..1).each do |i| %>
  <%= f.radio_button :rating, i, :id => "star#{i}" %>
  <% end %>
</div>

(1..5) goes from 1, 2, 3, 4, 5. What is the correct way of going 5, 4, 3, 2, 1?

like image 330
hellomello Avatar asked Dec 27 '22 01:12

hellomello


1 Answers

You can do downto

<div class="field-container rating">
  <% 5.downto(1) do |i| %>
  <%= f.radio_button :rating, i, :id => "star#{i}" %>
  <% end %>
</div>
like image 118
oldergod Avatar answered Jan 08 '23 23:01

oldergod