zombocom/wicked

Update doesn't go to next step

noff opened this issue · 3 comments

noff commented

Rails 5.2.3
Wicked gem wicked (1.3.4)

Controller:

class WizardStudentController < ApplicationController

  include Wicked::Wizard

  steps :personal, :avatar, :socials, :current_work, :debts, :insurance, :motivation, :ambitions, :forecast, :education, :documents

  def show
    @user = current_user
    redirect_to dashboard_path unless @user.applicant?

    case step
    when :personal
    when :avatar
    when :socials
    when :current_work
    end
    render_wizard
  end


  def update
    @user = current_user
    redirect_to dashboard_path unless @user.applicant?

    case step
    when :personal
      @user.update params[:user].permit(:first_name, :last_name)
    when :avatar
    when :socials
    when :current_work
    end
    render_wizard
  end

end

View personal.slim:

.container
  .row
    .col-md-8
      = simple_form_for @user, url: wizard_path, method: :put do |f|
        = f.input :first_name
        = f.input :last_name
        = f.submit t('active_admin.next'), class: 'btn btn-primary'
    .col-md-4
      div Personal info

When I click form button, user info is saved to database, but I stay on the same step - personal.

According to README:

We're passing render_wizard our @user object here. If you pass an object into render_wizard it will show the next step if the object saves or re-render the previous view if it does not save.

So it re-render the previous step even if it saves the model properly

So it re-render the previous step even if it saves the model properly?

I'm not totally sure. Reading the code I think that's what's happening

def render_wizard(resource = nil, options = {}, params = {})
process_resource!(resource, options)
if @skip_to
url_params = (@wicked_redirect_params || {}).merge(params)
redirect_to wizard_path(@skip_to, url_params), options
else
render_step(wizard_value(step), options, params)
end
end
def process_resource!(resource, options = {})
return unless resource
if options[:context]
did_save = resource.save(context: options[:context])
else
did_save = resource.save
end
if did_save
@skip_to ||= @next_step
else
@skip_to = nil
end
end

try render_wizard @user ? You don't provide a record.

Is this resolved? Still an issue? If so can someone give me a reproduction application? https://www.codetriage.com/example_app