Sunday, January 3, 2010

Re: [Rails] Re: Question regarding entering data in a has_many relations

You would want each_with_index.

<ul>
  <% @recipie.steps.each do |step, index| %>
    <li><%= index %>: <%= step.step %></li>
  <% end %>
</ul>

A little cleaner, and handles updating the index for you.

-Steve 

On Sun, Jan 3, 2010 at 12:47 PM, Ooh_Gravy <shareef@jalloq.co.uk> wrote:
So answering my own question, is this ok or is there a cleaner way to
do it?

       <ul>
               <% index = 1 %>
               <% @recipe.steps.each do |step| %>
                       <li><%= index %>: <%= step.step %></li>
                       <% index += 1 %>
               <% end %>
       </ul>

Thanks a lot.

On Jan 3, 5:10 pm, Ooh_Gravy <shar...@jalloq.co.uk> wrote:
> OK, thanks.  What I wanted to do was this:
>
>         <ul>
>                 <% @recipe.steps.each do |step| %>
>                         <li><%= step.id %>: <%= step.step %></li>
>                 <% end %>
>         </ul>
>

--

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.



--

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate