3

I've found almost what I needed in a previous question: Wicked Wizard dynamic step order

Unfortunately, I'm still struggling with my problem. I want to make my Wicked Wizard have totally dynamic step order (besides the first step). Each response is a database item belonging to each Question database item. I want to use the next_question attribute from the Response that is selected to determine which step will come next.

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
4

1 回答 1

1

当我在 Rails 3.2 中尝试类似的策略时,before_filter它给了我一个错误,建议我改用prepend_before_filter它,这很有效。看起来 Rails 4: 中存在类似的方法prepend_before_action,所以它应该适合你。此外,我将元素转换为符号(而不是字符串),因此在您的情况下,它类似于self.steps = Question.pluck(:name).map(&:to_sym). 希望有帮助!

于 2017-01-21T23:08:48.690 回答