未初始化的常量Payroll_Manager ::教师

时间:2016-02-28 04:43:44

标签: ruby-on-rails compiler-errors

我正在为工资薪水制定薪资系统。我只需要选择一个月,一年,然后按"创建工资单",并为所有教师创建工资单

mockup

我创建了方法"创建"在payroll_controller.rb中:

Payroll_Manager.new(params[:month], params[:year]).crear_liquidaciones_del_periodo()

Payroll_Manager位于文件app / helpers / payroll_manager.rb

class Payroll_Manager < PayrollsController

  def initialize(month, year)
    @month = month
    @year = year
  end

  def crear_liquidaciones_del_periodo
    Teachers.each do |t|
      t.payrolls.create(@month, @year)
    end
  end
end

最后,我有了codel payroll.rb

class Payroll < ActiveRecord::Base
  belongs_to :teacher
  has_many :payroll_lines

  def period
    period = month + " " + year
  end

  validates :month, presence: true
  validates :year, presence: true

  class Payroll < ActiveRecord::Base
    #gross_total, retention_total, neto_total
    before_save :calculate_payroll

  private
    def calculate_payroll
      calculate_gross_total
      calculate_retention_total
      calculate_net_total
    end

    def calculate_gross_total
      self.gross_total = 0
      ## Concepto.where(type: 1)
      haberes = Concepts.all.select{ |c| c.type == 1 }

      haberes.each do |h|
        parametros_para_linea = {concept_id: h.id, subtotal: h.amount}
        self.payroll_line.create(parametros_para_linea)
        self.gross_total += h.amount
      end
    end

    def calculate_retention_total
      self.retention_total = 0
      ## Concepto.where(type: 0)
      retencion = Concepts.all.select{ |c| c.type == 0 }

      retencion.each do |r|
        parametros_para_linea = {concept_id: h.id, subtotal: h.amount}
        self.payroll_line.create(parametros_para_linea)
        self.retention_total += r.amount
      end
    end

    def calculate_net_total
      self.net_total = gross_total - retention_total
    end
  end
end

...当我点击&#34;创建工资单&#34;按钮,我有错误:

  

未初始化的常量Payroll_Manager ::教师

enter image description here

请帮助我。

1 个答案:

答案 0 :(得分:0)

payroll_manager.rb中的类定义应该是PayrollManager,而不是Payroll_Manager。