1

我将此添加到我的控制器中:

class HtmlreportController < ApplicationController
    def index
        @report = Report.new
        @report_presenter = ReportPresenter.new(@report_presenter)
    end
end

然后将此演示者添加到 /app/presenters

# app/presenters/htmlreport_presenter.rb
class ReportPresenter
    def initialize(report)
        @report = report
    end

    def pass_fail(view)
        arrs = ['onemon.rb','twomon.rb','threemon.rb','fourmon.rb','fivemon.rb']

        arrs.each do |arr|
            shortname = File.basename("#{arr}", ".rb")
            newest_file = Dir.glob("ScriptResults/#{shortname}/*").max

            @reporter = File.readlines("/Users/username/Automation/Code/Reports/MonthlyTracking/#{newest_file}")

            if @reporter.grep(/test failed/).any?
                view.concat content_tag(:div, 'FAILED', class: 'results_fail')
            else
                view.concat content_tag(:div, 'PASSED', class: 'results_pass')
            end

       end   
    end
end

在我看来:

<% title "HTML Report" %>
<!-- This is where the HTML Report lies -->   

<h1>HTML Report for Marines.com Daily Monitoring</h1>

<div>View the grids below for the following results:</div>

<div id="results">   
    <div class="results_grid">
        <div class="results_title">Xbox</div>
        <%= @report_presenter.show_credentials(self) %>
    </div>
</div>

但是,运行它时出现此错误:@report = Report.new行的未初始化常量 HtmlreportController::Report

如何对其进行初始化以使其将演示者中的功能识别到我的视图中?

4

0 回答 0