Question

I have watched Wicked forms with wizard and I am trying to do my own form, I have the following:

Employees_controller.rb

class EmployeesController < ApplicationController
    def index
        @employees = Employee.all
    end

    def show
        @employee = Employee.find(params[:id])
    end

    def new
        @employee = Employee.new
    end

    def create
        @employee = Employee.new(params[:employee])
        if @employee.save
            flash[:notice] = 'An employee has been created.'
            redirect_to employee_admission_steps_path(:employee_id => @employee.id)
        else
            flash[:error] = 'An error occurred please try again!'
            redirect_to '/dashboard'
        end
    end

    def edit

    end

    def update

    end

    def destroy

    end
end

Employee_admission_steps_controller.rb

class EmployeeAdmissionStepsController < ApplicationController
    include Wicked::Wizard
    steps :employee_admission1 , :employee_admission2

    def show
        @employee = Employee.find(params[:employee_id])
        render_wizard
    end

    def update
        @employee = Employee.find(params[:employee_id])
        @employee.update_attributes(params[:employee])
        render_wizard(@employee)
    end

    private

    def finish_wizard_path
        users_path
    end
end

employee_admission1.html.erb and employee_admission2.html.erb

both files have the following line in the begining:

<%= simple_form_for @employee, url: wizard_path(employee_id: @employee.id), method: :put do |f| %>

and the following line in the end:

   <%= f.submit 'Next', :class => "btn btn-success" %>
<% end %>

routes.rb

 resources :employees
  scope 'employees/:employee_id' do
    resources :employee_admission_steps
  end

Now my main problem is after filling employee_admission1.html.erb and press next , it goes to finish wizard. how to make it go to employee_admission2.html.erb ?

Was it helpful?

Solution

Change the top line in your forms to:

<%= simple_form_for @employee, url: wizard_path, method: :put do |f| %>

Otherwise, it thinks the current step is something like employee_id=1 or employee_id=99 (depending on the id of the employee you are working with) when it should be employee_admission1. And since it doesn't know what step employee_id=1 is, it jumps to the end of the wizard.

Check the params in your server log and you'll see what I mean.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top