我把它添加到我的控制器:
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>
但是,我在运行时遇到此错误:未初始化的常量HtmlreportController :: Report ,用于行 @report = Report.new
如何初始化它以使其在我的视图中识别我的演示者中的功能?