0

In rails app I use wicked gem to create wizard(https://github.com/schneems/wicked/)

I want protect my wizard and render only concrete step after check.

In fact render_wizard method can accept only instance:

render_wizard @product

Is it possible somehow render only allowed step in show action? I need something like:

if params[:id] == @my_request_model.current_state
  render_wizard
else
  render_wizard @my_request_model.current_state

Redirecting here is not a good idea because update action already make redirect

Cœur
  • 37,241
  • 25
  • 195
  • 267
Volodymyr
  • 1,136
  • 3
  • 11
  • 28

1 Answers1

0

Hmm, are you trying to add validations to your form for each wizard step? If so, you can do the following:

In your model

validate :foo if step_1
validate :bar if step_2

def step_1
  form_progress == 1
end

def step_2
  form_progress == 2
end

Add a migration to add form_progress column to your model.

On each step form add a hidden_field for form_progress and set the value to the number of that step.

f.hidden_field :form_progress, value: 1

So this way, the user can only advance to the next step if they pass the validations.

miahabdu
  • 614
  • 4
  • 5