OK, thanks. What I wanted to do was this:
<ul>
<% @recipe.steps.each do |step| %>
<li><%= step.id %>: <%= step.step %></li>
<% end %>
</ul>
but that would now result in:
* 1: This is the first step
* 3: This is the second step
So I now need to use a helper to generate a step index I can use to
display to the user.
On Jan 3, 3:07 pm, Rodrigo Dellacqua <[email protected]> wrote:
> Gravy,
>
> If I now delete the second step and add another I now have id's 1 and 3. id
>
> > 2
> > has been 'consumed' which means that a simple loop using the id's to
> > generate an html list won't work.
>
> Answering both of your questions, that's how the DB works. It has an
> internal sequence, which it increments for each new insert operation.
>
> Simple loop using ids? What do you mean? Why would you do that?
>
> for step in @recipes.steps
>
> end
>
> []'s
> Rodrigo Dellacqua
>
> On Sun, Jan 3, 2010 at 10:38 AM, Ooh_Gravy <[email protected]> wrote:
> > OK, so my previous errors seemed to be due to a Windows environment
> > issue. Now I'm back on my Mac things are all working.
> > Anyway....thanks for the help and pointing in the direction of those
> > screencasts. I found Ryan's updated nested form example on Github
> > (complex-form-examples) and it's just what I was looking for.
> > However, I do have a further question regarding table id's.
>
> > In my application I have a recipe with multiple steps. Using the
> > complex form example, I can create, edit and delete the steps of a
> > recipe. However, the step id's are always incrementing. I.E. I
> > create two steps which have id's of 1 and 2 respectively. If I now
> > delete the second step and add another I now have id's 1 and 3. id 2
> > has been 'consumed' which means that a simple loop using the id's to
> > generate an html list won't work.
>
> > Is this just the way table id's work when they are deleted or is it
> > specific to this implementation in the complex form example? Is the
> > solution to work out how many steps are present and increment an
> > integer to use as the index in the template?
>
> > Thanks.
>
> > On Dec 29 2009, 8:38 pm, Ooh_Gravy <[email protected]> wrote:
> > > So I've been reading just that blog entry but can't get it to work.
> > > I've create a "recipes" table with name, author and a description.
> > > ...
>
> > --
>
> > 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 [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<rubyonrails-talk%[email protected]>
> > .
> > 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.