2009-06-03 2 views
0

InvoicingAndDelivery.report_lines를 호출 한 다음 해당 결과의 배열을 제공하려고하지만 작동하지 않습니다. 어떤 아이디어?레일에서 자체 클래스를 초기화하는 방법은 무엇입니까?

class InvoicingAndDelivery < Report 
    include DateExtentions 
    attr_accessor :report_lines, :tba_line, :sum_line 

    def initialize(part_or_service_ids, start_date, to_date) 

    # @report_lines = [] 

    number_of_months(start_date,to_date).times do |i| 
     start_date = start_date + i.months 
     l = InvoicingAndDeliveryReport.new 
     l.month = start_date.strftime("%m/%Y") 
     l.work_profile = WorkProfileLine.delivery_amount_for_serivces_in(part_or_service_ids, start_date) 
     l.forecast_delivery = LineItem.forecast_delivery_amount_for_services_in(part_or_service_ids, start_date) 
     l.invoicing = InvoiceLine.invoices_total_for_services_in(part_or_service_ids, start_date) 
     l.projected_invoices = InvoiceLine.projected_invoice_total_for_services_in(part_or_service_ids, start_date) 
     l.costs = LineItem.costs_total_for_services_in(part_or_service_ids, start_date) 
     l.gross_profit = l.invoicing - l.costs 
     l.opportunities = LineItem.oportunities_value_for_services_in(part_or_service_ids, start_date) 
     # @report_lines<< l 
    end 

    @tba_line = InvoiceLine.service_type(@part_or_service).tba_lines.sum("invoice_lines.sell_price * invoice_lines.quantity").to_f 
    @sum_line = get_sum_line 
    end 

답변

1

보고서 란 무엇입니까?

당신이 가지고 있으면 안되는 것을 덮어 쓸 가능성이 있습니다 ... 초기화 할 때 슈퍼를 호출해야하거나, 앞서 언급 한 것처럼 콜백을해야합니다.

+0

나는 수퍼 클래스를 사용하는 방법뿐만 아니라 추상 클래스를 사용하는 방법에 대한 책을 정말로 읽을 필요가있다. 답변 해 주셔서 감사합니다. –

1

InvoicingAndDeliveryActiveRecord::Base에서 내려 경우 shouldn't override initialize. 대신이 코드를 after_initialize에 넣으십시오.

+0

감사합니다.이 클래스를 ActiveRecord로 사용하지는 않지만 어쨌든 팁을 주셔서 감사합니다. –

관련 문제