我几乎找到了上一个问题所需的内容:Wicked Wizard dynamic step order
不幸的是,我仍然在努力解决我的问题。我想让我的邪恶巫师有完全动态的步骤顺序(除了第一步)。每个响应都是属于每个Question数据库项的数据库项。我想使用选择的Response中的next_question属性来确定接下来将采用哪个步骤。
class ExperimentsController < ApplicationController
def create
@experiment = Experiment.new
@experiment.save(validate: false)
redirect_to experiment_steps_path(@experiment, Experiment.steps.first)
end
...
private
def experiment_params
params.require(:experiment).permit(:name, :questions, :responses, :form_step)
end
end
class ExperimentStepsController < ApplicationController
include Wicked::Wizard
before_action :set_steps
before_action :setup_wizard
def show
@experiment = Experiment.find(params[:experiment_id])
@next_question = Response.find(params[:next_question])
jump_to(:next_question)
render_wizard
end
private
def set_steps
self.steps = Question.pluck(:name)
end
def response_params
params.fetch(:response, {}).permit(:next_question)
end
end
答案 0 :(得分:1)
当我在使用$sql = "INSERT INTO TABLE_NAME (pm, from, to, sub, mess, date) VALUES ('$From', '$To', '$Sub', '$Mess', '$Date'");
的Rails 3.2中尝试类似的策略时,它给了我一个错误,建议我使用before_filter
代替,这是一种享受。看起来Rails 4中存在类似的方法:prepend_before_action
,所以这应该适合你。此外,我将元素转换为符号(而不是字符串),因此在您的情况下,它将类似于prepend_before_filter
。希望有所帮助!