Вы можете достичь этого разными способами. Следуя своей идее цикла, вы также можете использовать each_with_index
в первом цикле:
<% @trial.treatment_selections.each_with_index do |t, outer_index| %>
<% t.establishment_methods.each_with_index do |e, inner_index| %>
<% if outer_index == 0 && inner_index == 0 %>
<%= inner_index %> | <%= e.assessment_date %><br />
<% end %>
<% end %>
<% end %>
Но лучший способ сделать это - всего одна строка
0 | <%= @trial.treatment_selections.first&.establishment_methods.first&.assessment_date %>
Индекс всегда будет 0
, если вы хотите его напечатать.