gpt4 book ai didi

ruby-on-rails-3 - Wicked Rails Gem 帮助接线

转载 作者:行者123 更新时间:2023-12-04 07:19:33 25 4
gpt4 key购买 nike

我想做一个多步骤表单来接收新信息。上一页我要收集姓名/联系信息,下一页我要收集病史,第三页我要收集人口统计信息。

我已经安装了 Wizard gem 并生成了一个专用 Controller 。我在上面看到的所有教程都适用于设计和注册过程,所以我对 Controller 操作和实例变量以及我应该如何编写它们有点迷茫。

想知道除了注册教程之外,是否有人有教程可以帮助我学习如何将这一切连接起来。

如有任何指点或帮助,我们将不胜感激。

编辑:

我认为我的问题出在向导的 Controller 上。

在显示和更新操作中,演示显示声明变量

@user = current_user

这很好,但这是我不需要的辅助方法。我需要创建一个患者,将 patient_id 存储在我在主患者 Controller 的创建操作中执行的 session 中。然后以某种方式将其传递给 patientsteps Controller 。

这是我在耐心的步骤中尝试过的

class PatientstepsController < Wicked::WizardController
before_filter :authenticate_user!

steps :medical, :summary

def show
@patient = Patient.find(params[:patient_id])
render_wizard
end

def update
@patient = Patient.find(params[:id])
@patient.attributes = params[:patient]
render_wizard @patient
end
end

当我这样做时,我无法找到没有 ID 的患者。我知道我做错了,但我不确定如何传递在我的患者 Controller 创建操作中创建的 patient_id。

患者 Controller 创建:

 def create
@patient = Patient.new(params[:patient])

if @patient.save
session[:patient_id] = @patient.id
redirect_to patientsteps_path, notice: "Patient was successfully created."
else
render :new
end
end

最佳答案

在您的 show 操作中,您应该使用 session[:patient_id] 而不是 params[:patient_id],因为患者的 ID 存储在 session 中,而不是在 params 散列中。

然后在更新操作中,您将在 params[:patient_id] 中收到患者 ID,而不是 [:id],因为 wicked 使用 params[:id] 来识别向导正在进行的步骤。

关于ruby-on-rails-3 - Wicked Rails Gem 帮助接线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15980632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com