邪恶的向导动态步骤顺序

时间:2014-08-12 18:43:22

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

我试图根据之前选择的选择来改变邪恶巫师中的步骤顺序。

所以目前我已经完成了所有步骤:

class WWTestController < ApplicationController
  include Wicked::Wizard
  steps :first_page,:optional_page,:second_page

   def show
     @event_object = EventObject.find(params[:event_object_id])

     render_wizard
   end

   def update
     @event_object = EventObject.find(params[:event_object_id])
     @event_object.update_attributes(event_object_params)

     render_wizard @event_object
   end

   private

   def event_entry_params
    params.fetch(:event_object, {}).permit(:choice_a)
   end

end

如果选项:choice_a等于2 ,我只想包含:optional_page 步骤。我尝试了各种配置,但我遇到的真正问题是,如果他们回到:firstpage 并更改步骤并不总是正确的。我确信有人对此有好的方法,我们将非常感谢任何帮助!

1 个答案:

答案 0 :(得分:2)

  def show
    @event_object = EventObject.find(params[:event_object_id])

    # Extra logic based on flow steps - when to skip sth.
    case step
    when :optional_page
      skip_step unless @event_object.choice_a == 2
    end

    render_wizard
  end