0

I have a bit of a complicated wizard and I'd like to route the user based on their entries to the form.

I have listed the steps as follows:

steps :weight_loss_history, :health_conditions, :cancer, :weight_mindset, :diabetes, :diet_information, :heart,  :food_intake

...and my update and routing functions are as follows:

def update
    @remote = current_remote
    params[:remote][:step] = step
    atts = Remote.fix_attributes(params[:remote])
    @remote.attributes = atts # equal to large hash of params
    find_route(@remote)
end

def find_route(info)
    if info[:cancer]
        puts "cancer..." # I never see this in the console
        jump_to(:cancer)
    else
        render_wizard info
    end
end

Does anyone have a good implementation of using Wicked to route users based on their choices?

Jeremy Thomas
  • 6,240
  • 9
  • 47
  • 92

1 Answers1

0

The problem here is in an info attribute that you pass into find_route. I guess that you have to rewrite your action like that:

def update
  @remote = current_remote
  params[:remote][:step] = step
  atts = Remote.fix_attributes(params[:remote])
  @remote.attributes = atts # equal to large hash of params
  return jump_to(:cancer) if step == :cancer
  return render_wizard info
end

if you push from step otherwise i guess that @remote doesn't contains :cancer key and if case of using ruby hash you have to set key like that:

@remote[:cancer] = true
return jump_to(:cancer) if @remote[:cancer] 
return render_wizard info
ilgam
  • 4,092
  • 1
  • 35
  • 28