gpt4 book ai didi

ruby-on-rails - 未初始化的常量Payroll_Manager::Teachers

转载 作者:行者123 更新时间:2023-12-02 11:01:55 24 4
gpt4 key购买 nike

我正在建立工资系统。我只需要选择一个月,一年,然后按“创建工资单”,然后为所有老师创建工资单

mockup

我在payroll_controller.rb中创建了方法“create”:

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

...当我单击“创建工资单”按钮时,出现错误:

uninitialized constant Payroll_Manager::Teachers



enter image description here

请帮我。

最佳答案

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

关于ruby-on-rails - 未初始化的常量Payroll_Manager::Teachers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35678778/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com