Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

previous_step defaults to first step, if current_step == first_step #298

Open
rjaus opened this issue May 17, 2023 · 1 comment
Open

previous_step defaults to first step, if current_step == first_step #298

rjaus opened this issue May 17, 2023 · 1 comment

Comments

@rjaus
Copy link

rjaus commented May 17, 2023

  def previous_step(current_step = nil)
    return @previous_step if current_step.nil?
    index =  steps.index(current_step)
    step  =  steps.at(index - 1) if index.present? && index != 0
    step ||= steps.first
  end

When on the first step of the wizard, I would have expected the previous_step to be nil. But it seems to default to the first step.

Is there a reason for that?

I realise I can monkey patch in a change here. But I was just trying to understand the design decision.

The same occurs for the previous/next_wizard_path view helpers.

@schneems
Copy link
Member

schneems commented May 18, 2023

I wanted to always return a result and instead use predicate methods to check for edge conditions. What do the predicate methods return?

past_step?(step)                              # does step come before the current request's step in wizard_steps
future_step?(step)                            # does step come after the current request's step in wizard_steps
previous_step?(step)                          # is step immediately before the current request's step
next_step?(step)  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants