Rails 4 + Wicked:使用params路由

时间:2016-11-09 15:22:03

标签: ruby-on-rails forms ruby-on-rails-4 wicked-gem

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

我列出了以下步骤:

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根据他们的选择路由用户?

1 个答案:

答案 0 :(得分:0)

这里的问题是你传递给find_route的info属性。 我想你必须重写你的行动:

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不包含:癌症密钥,如果使用ruby哈希的情况你必须设置这样的键:

@remote[:cancer] = true
return jump_to(:cancer) if @remote[:cancer] 
return render_wizard info