Answer the question
In order to leave comments, you need to log in
Who will tell you how to display the serial number in the element in ruby?
Good day!
There is a small problem (FE itself) with ruby:
= link_to 'blah-blah-blah', '#', class: 'some_class' do
%span.order_number='Нужно вывести порядковый номер данной ссылки'
Answer the question
In order to leave comments, you need to log in
Pure Ruby: apidock.com/ruby/Enumerable/each_with_index
- array.each_with_index do |element, index|
= link_to 'blah-blah-blah', '#', class: 'some_class' do
%span.order_number = index
link_to is not Ruby, it's a helper from the Ruby on Rails framework.
If the array is iterated using the each method, then it can be replaced with .each_with_index, while the 2nd parameter will be passed to the block - a number from 0 to the number of elements in the array minus one. This parameter can serve as a serial number of the link.
Isn't it easier to wrap it in a tag li
? He will do his own thing.
Something like this
%ol
- for link in links do
%li
= link_to link.path, class: 'some_class' do
= link.name
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question