# Sequential steps in rails

**URL:** <https://www.ruby-forum.com/t/sequential-steps-in-rails/183054>\
**Category:** Rails\
**Created:** [February 7, 2010, 4:08am UTC](https://www.ruby-forum.com/t/sequential-steps-in-rails/183054 "2010-02-07T04:08:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 7, 2010, 4:08am UTC](https://www.ruby-forum.com/t/sequential-steps-in-rails/183054/1 "2010-02-07T04:08:05Z")

</div>

A lot of times websites simulate wizards where you enter some  
information and click the next button to move to the next step before  
completing the form. I’m looking at some code that attempts to achieve  
this, but it has a “direction” parameter that I’m not sure what it does.  
All I know is that it is either a -1 or 1 value:

def sequence(method\_pre)  
@step = (params[:step] || 0).to\_i  
@direction = (params[:direction] || 1).to\_i

if @step == 0  
@step = 1

elsif @direction == -1  
send("#{method\_pre}\_update\_values", @step)  
@step -= 1

elsif send("#{method\_pre}\_validate", @step)

if @step == send("#{method\_pre}\_num")  
send("#{method\_pre}\_final")  
else  
@step += @direction  
end  
else  
flash.now[:error]

I’m not exactly sure what direction does here and why it’s only a -1 or  
1 value. Also, I noticed these possible combinations:  
(step 1 direction 1)(step 2 direction 1)(step 3 direction 1)(step 0  
direction 1)(step 2 direction -1)(step 3 direction -1)  
Any ideas? Thanks.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 7, 2010, 1:08pm UTC](https://www.ruby-forum.com/t/sequential-steps-in-rails/183054/2 "2010-02-07T13:08:53Z")

</div>

I looks like @step tells you what step the user is currently at, and  
that @direction tells you whether he pressed the “previous step” or  
“next step” button.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 7, 2010, 2:21pm UTC](https://www.ruby-forum.com/t/sequential-steps-in-rails/183054/3 "2010-02-07T14:21:16Z")

</div>

Sharagoz – wrote:

> I looks like @step tells you what step the user is currently at, and  
> that @direction tells you whether he pressed the “previous step” or  
> “next step” button.

So if that’s the case, why would the params method be captured here for  
both :step and :direction. Thanks for the response.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 8, 2010, 12:16am UTC](https://www.ruby-forum.com/t/sequential-steps-in-rails/183054/4 "2010-02-08T00:16:37Z")

</div>

On Feb 7, 8:21 am, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Sharagoz – wrote:
> 
> > I looks like @step tells you what step the user is currently at, and  
> > that @direction tells you whether he pressed the “previous step” or  
> > “next step” button.
> 
> So if that’s the case, why would the params method be captured here for  
> both :step and :direction.

What? You’ll need to explain what you mean by “the params method be  
captured” if you’re looking for an answer…

–Matt JOnes
