I am attempting keeping track of the number of steps in a technique. In the form I am creating, users can add new steps to a set of instructions. Right now, I have default fields for steps 1-7. Adding one step, gets you step 8. The problem is that subsequent steps are numbered '8' also.

2 Answers
2

Ok, I'm a little confused by what you are doing, but I'm going to try and make some suggestions.

Rather than use link_to_function, use link_to_remote. Link to function calls javascript, but what you actally want to do is call back to a controller that then runs some rjs to either replace the full partial, or more likely, append the new partial (containing the step) to the end of your current steps.

This is similar to all those examples you will have seen where people append a comment to the end of their blog comments (expect using link_to_remote rather than remote_form_for) see 3/4 of the way through http://media.rubyonrails.org/video/rails_blog_2.mov

I suggest using link_to_remote as RichH suggests. The trick for you it seems is keeping track of @i. I'd either put it as a URL parameter in link_to_remote, or in the session object. I'd suggest the session—it seems easier.