0

用向导观看了 Wicked 表格,我正在尝试制作自己的表格,我有以下内容:

员工控制器.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 和 employee_admission2.html.erb

这两个文件的开头都有以下行:

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

最后是以下行:

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

路线.rb

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

现在我的主要问题是在填写 employee_admission1.html.erb 并按 next 之后,它会完成向导。如何让它去 employee_admission2.html.erb ?

4

1 回答 1

1

将表单中的第一行更改为:

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

否则,它认为当前步骤类似于employee_id=1employee_id=99(取决于与您一起工作的员工的 ID)何时应该是employee_admission1。而且由于它不知道步骤employee_id=1是什么,所以它跳到向导的末尾。

检查服务器日志中的参数,您就会明白我的意思。

于 2013-09-12T21:30:37.910 回答