Zakaria
Zakaria

Reputation: 1013

Variables to work with loops in rails

The Symfony framework has loop_index, first and last variables for working with loops.

{% for each link in links %}
    {% if loop_index == first %}
       .....
    {% else %}
       ....
    {%endif %}

{% end %}

Are there such variables or functions in rails?

Upvotes: 0

Views: 43

Answers (1)

Erez Rabih
Erez Rabih

Reputation: 15788

Not exactly but you can use each_with_index:

{% links.each_with_index do |link, index| %}
    {% if index == 0 %}
       .....
    {% else %}
       ....
    {%endif %}

{% end %}

Upvotes: 3

Related Questions