Rails 4 +邪恶:使用参数来路由
问题描述:
我有一个复杂的向导,我想根据他们的条目路由到窗体的用户。Rails 4 +邪恶:使用参数来路由
我列出的步骤如下:
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
有没有人有一个良好的执行使用妖兽路线用户基于他们的选择?
答
这里的问题是你传递给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