E
E
eldar_web2015-12-01 20:24:33
Ruby on Rails
eldar_web, 2015-12-01 20:24:33

How in Ruby on Rails can you find out what number this element is from the parent element?

For example, there are links to the Mercedes and Models tables.
So I display the models of this Mercedes through the loop:

<% Mercedes.each do |m| %>
<% p m.models.name # Как здесь узнать какой по числу это модель
<% end %>

Here, when outputting, how can you find out what the number of element is,

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Grudinkin, 2015-12-01
@Hunt666

I guess it will be something like:
p a.index(m.models.name)for an array and
p a.key(m.models.name)for a hash

_
_ _, 2015-12-01
@AMar4enko

each_with_index do |item, index|
Or |index,item| I do not remember

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question