所以我一直试图在名为" metasploit_host_notes的表中显示来自mysql数据库的数据。我想在现有的表格中添加一个标签,名为" Notes"并显示该数据。我不知道我错过了什么,但我一直收到这个错误:
显示 /Users/angelispseftis/RubymineProjects/vapt/app/views/engagements/_metasploit_tabview.erb 第40行引出的地方:
未定义的局部变量或方法`metasploit_host_notes'对
<#:0x007fe859c93788>提取的来源(第40行):
38 <div class="mTop10"> 39 <div id="metasploit_host_notes"> 40 <%= render partial: "/engagements/metasploit_notes", locals: {metasploit_host_notes: metasploit_host_notes} %> 41 </div> 42 </div> 43 </div>
_metasploit_tabview.erb
<div>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
<a href="#metasploit_host_tabview" aria- controls="metasploit_host_tabview" role="tab" data-toggle="tab">Hosts</a>
</li>
<li role="presentation">
<a href="#metasploit_service_tabview" aria-controls="metasploit_service_tabview" role="tab" data-toggle="tab">Services</a>
</li>
<li role="presentation">
<a href="#metasploit_vulns_tabview" aria- controls="metasploit_vulns_tabview" role="tab" data- toggle="tab">Vulnerabilities</a>
</li>
<li role="presentation">
<a href="#metasploit_notes_tabview" aria-controls="metasploit_notes_tabview" role="tab" data-toggle="tab">Notes</a>
</li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="metasploit_host_tabview">
<div class="mTop10">
<div id="metasploit_host">
<%= render partial: "/engagements/metasploit_host", locals: {metasploit_report: metasploit_report, engagement: engagement} %>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="metasploit_service_tabview">
<div class="mTop10">
<div id="metasploit_service">
<%= render partial: "/engagements/metasploit_service", locals: {metasploit_report: metasploit_report} %>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="metasploit_vulns_tabview">
<div class="mTop10">
<div id="metasploit_vulns">
<%= render partial: "/engagements/metasploit_vulns", locals: {metasploit_report: metasploit_report} %>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="metasploit_host_notes_tabview">
<div class="mTop10">
<div id="metasploit_host_notes">
<%= render partial: "/engagements/metasploit_notes", locals: {metasploit_host_notes: metasploit_host_notes} %>
</div>
</div>
</div>
</div>
</div>
</div>
的 _metasploit_notes.erb
<h3>Host Notes</h3>
<table class="table table-striped table-bordered" id="metasploit_host_notes">
<thead>
<th>Note ID</th>
<th>Created At</th>
<th>Updated At</th>
<th>Ntype</th>
<th>Workspace ID</th>
<th>Service ID</th>
<th>Critical</th>
<th>Seen</th>
<th>Vuln ID</th>
<th>Data</th>
</thead>
<tbody>
<% unless @metasploit_report.metasploit_host.blank? %>
<% @metasploit_report.metasploit_hosts.each do |host| %>
<% unless host.metasploit_host_notes.blank? %>
<% host.metasploit_host_notes.each do |host_note| %>
<tr>
<td><%= host_note.note_id %></td>
<td><%= host_note.metasploit_created_at %></td>
<td><%= host_note.metasploit_updated_at %></td>
<td><%= host_note.ntype %></td>
<td><%= host_note.workspace_id %></td>
<td><%= host_note.service_id %></td>
<td><%= host_note.critical %></td>
<td><%= host_note.seen %></td>
<td><%= host_note.vuln_id %></td>
<td><%= host_note.data %></td>
</tr>
<% end %>
<% end %>
<% end %>
<% end %>
</tbody>
</table>
show.html.erb
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs vTabs" role="tablist" id="myTab">
<li role="presentation"><a href="#metasploit" aria-controls="metasploit" role="tab" class="tab-pane active" data-toggle="tab">Metasploit</a></li>
<li role="presentation"><a href="#creds" aria-controls="creds" role="tab" data-toggle="tab">Creds</a></li>
<li role="presentation"><a href="#vulns" aria-controls="vulns" role="tab" data-toggle="tab">Vulns</a></li>
<li role="presentation"><a href="#nmap" aria-controls="nmap" role="tab" data-toggle="tab">Nmap</a></li>
<li role="presentation"><a href="#nessus" aria-controls="nessus" role="tab" data-toggle="tab">Nessus</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content" id="myTabContent">
<div role="tabpanel" class="tab-pane active" id="metasploit">
<div class="mTop10">
<%= select_tag('metasploit_report', options_for_select(@metasploit_reports.collect{ |u| ["#{u.created_at} (#{u.user.username})", u.id] }), onchange: "var element = this.value;$('.ajaxLoader').show(); $.get('/engagements/#{@engagement.id}/metasploit/'+this.value+'/metasploit_reports').done(function(h) {$('#metasploit_full_details_link').attr('href', '/engagements/#{@engagement.id}/metasploit/'+element);$('.ajaxLoader').hide();});", class: 'smSelect') unless @metasploit_reports.empty? %>
<% unless @metasploit_reports.empty? %>
<%= link_to "View full metasploit result", engagement_metasploit_path(@engagement.id, @metasploit_reports.first.id), id: "metasploit_full_details_link", target: "_blank" %>
<%# if @metasploit_reports.first.is_completed %>
<div id="metasploitListHolder">
<%= render partial: "metasploit_tabview", locals: {metasploit_report: @metasploit_reports.first, engagement: @engagement} %>
</div>
<%# end %>
<% end %>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="creds">
<%= render partial: "creds_info_tab" %>
</div>
<div role="tabpanel" class="tab-pane" id="vulns">
<div class="mTop10">
<% unless @nessus_policies.empty? %>
<% unless @nessus_policies.first.nessus_reports.first.blank? %>
<%= select_tag('nessus_policy', options_for_select(@nessus_policies.collect{ |u| ["#{u.nessus_reports.first.name} (#{User.find(u.user_id).username})", u.id] }), onchange: "$('.ajaxLoader').show();$.get('/engagements/#{@engagement.id}/nessus/'+this.value+'/vulns_reports').done(function(h) {$('.ajaxLoader').hide();});") unless @nessus_policies.empty? %>
<% end %>
<% end %>
<div id="vulnsChartsHolder">
<%= render partial: "vulns", locals: {nessus_policy: @nessus_policies.first, engagement: @engagement} %>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="nmap">
<div class="mTop10">
<%= select_tag('nmap_report', options_for_select(@nmap_reports.collect{ |u| ["#{u.created_at} (#{u.user.username}))", u.id] }), onchange: "var element = this.value;$('.ajaxLoader').show();$.get('/engagements/#{@engagement.id}/nmap/'+this.value+'/nmap_reports').done(function(h) {$('#nmap_full_details_link').attr('href', '/engagements/#{@engagement.id}/nmap/'+element);$('.ajaxLoader').hide();});", class: 'w400') unless @nmap_reports.empty? %>
<% unless @nmap_reports.blank? %>
<%= link_to "View full nmap result", engagement_nmap_path(@engagement.id, @nmap_reports.first.id), id: "nmap_full_details_link", target: "_blank" %>
<% end %>
<div id="nmapListHolder">
<%= render partial: "list_nmaps", locals: {nmap_report: @nmap_reports.first} %>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="nessus">
<div class="mTop10">
<% if !@nessus_policies.blank? && !@nessus_policies.first.nessus_reports.blank? %>
<%= select_tag('nessus_policy', options_for_select(@nessus_policies.collect{ |u| ["#{u.nessus_reports.first.name} (#{User.find(u.user_id).username})", u.id] }), onchange: "var element = this.value;$('.ajaxLoader').show(); $.get('/engagements/#{@engagement.id}/nessus/'+this.value+'/nessus_reports').done(function(h) {$('#nessus_full_details_link').attr('href', '/engagements/#{@engagement.id}/nessus/'+element);$('.ajaxLoader').hide();});", class: 'w400') unless @nessus_policies.empty? %>
<% end %>
<% unless @nessus_policies.blank? %>
<%= link_to "View full nessus result", engagement_nessu_path(@engagement.id, @nessus_policies.first.id), id: "nessus_full_details_link", target: "_blank" %>
<% end %>
<div id="nessusListHolder">
<%= render partial: "nessus_tabview", locals: {nessus_policy: @nessus_policies.first, engagement: @engagement} %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
第二个&#34; metasploit_host_notes&#34;第40行基本上是方法调用或局部变量。
{metasploit_host_notes: metasploit_host_notes}
我猜你没有定义一个名为metasploit_host_notes
的辅助方法,显然没有该名称的局部变量。我猜的是你想传递一个具有该名称的实例变量(@metasploit_host_notes
)。将控制器中的变量定义为正确的值,并将该段代码更改为:
{metasploit_host_notes: @metasploit_host_notes}
# |----- here