Sequential steps in rails

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.

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.

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.

On Feb 7, 8:21 am, John M. [email protected] 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs