邪恶的宝石只显示了一步

时间:2013-09-12 04:25:00

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 wicked-gem

我已经看过Wicked forms with wizard而我正在努力做自己的表格,我有以下内容:

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和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 %>

的routes.rb

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

现在我的主要问题是在填写employee_admission1.html.erb并按下接下来后,它将完成向导。如何进入employee_admission2.html.erb?

1 个答案:

答案 0 :(得分:1)

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

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

否则,它认为当前步骤类似employee_id=1employee_id=99(取决于您正在使用的员工的ID),应该是employee_admission1。由于它不知道步骤employee_id=1是什么,它会跳转到向导的末尾。

检查服务器日志中的参数,你会看到我的意思。