0

我有一个复杂的向导,我想根据用户的输入将用户路由到表单。

我列出的步骤如下:

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

...我的更新和路由功能如下:

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

有没有人可以很好地实现使用 Wicked 根据用户的选择来路由用户?

4

1 回答 1

0

这里的问题在于您传递给 find_route 的信息属性。我想您必须像这样重写您的操作:

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

如果你从一步推,否则我猜@remote 不包含 :cancer 键,如果使用 ruby​​ 哈希,你必须像这样设置键:

@remote[:cancer] = true
return jump_to(:cancer) if @remote[:cancer] 
return render_wizard info
于 2016-11-09T15:50:06.677 回答