簡體   English   中英

參數數目錯誤(1代表2),但我相信我要傳遞兩個

[英]Getting wrong number of arguments (1 for 2), but I believe I'm passing two

即使傳遞了兩個參數,我也得到了wrong number of arguments (1 for 2)

無論如何我都在嘗試..

這是應用程序跟蹤。

app/controllers/ips_dashboard_controller.rb:6:in `initialize'
app/controllers/ips_dashboard_controller.rb:82:in `new'
app/controllers/ips_dashboard_controller.rb:82:in `block (2 levels) in ips_dashboard'
app/controllers/ips_dashboard_controller.rb:81:in `each'
app/controllers/ips_dashboard_controller.rb:81:in `block in ips_dashboard'
app/controllers/ips_dashboard_controller.rb:74:in `each'
app/controllers/ips_dashboard_controller.rb:74:in `ips_dashboard'

在這里,我正在查找數據庫中的ip地址,並將數組傳遞給IP_data類,以在Seer :: visualize中使用。

# Begin lookups for tgt addresses
target_ip_data = Array.new
@tgt_ip_array = Array.new
@events.each do |ip_event|
  def get_target_ip(sid,cid)
    IpsIpHdr.where('sid =? and cid =?', sid, cid).first.ip_dst
  end
  tgt_ip = get_target_ip(ip_event.sid, ip_event.cid).to_s(16).rjust(8,'0').scan(/.{2}/).map(&:hex).join('.')
  target_ip_data.push(tgt_ip)
  @tgt_ip_hash = Hash[target_ip_data.group_by {|x| x}.map {|k,v| [k,v.count]}]
  @tgt_ip_hash.each do |t|
    @tgt_ip_array.push(IP_data.new(:ip => t[0],:count => t[1]))
  end
end
# End lookups for tgt addresses

我也嘗試過,但也出現錯誤。 undefined method 'ip' for ["172.31.251.13", 24]:Array

# Begin lookups for tgt addresses
target_ip_data = Array.new
@tgt_ip_array = Array.new
@events.each do |ip_event|
  def get_target_ip(sid,cid)
    IpsIpHdr.where('sid =? and cid =?', sid, cid).first.ip_dst
  end
  tgt_ip = get_target_ip(ip_event.sid, ip_event.cid).to_s(16).rjust(8,'0').scan(/.{2}/).map(&:hex).join('.')
  target_ip_data.push(tgt_ip)
  @tgt_ip_hash = Hash[target_ip_data.group_by {|x| x}.map {|k,v| [k,v.count]}]
  @tgt_ip_hash.each do |t|
    IP_data.new(t[0],t[1])
  end
end
# End lookups for tgt addresses 

這是錯誤

undefined method `ip' for ["172.31.251.13", 24]:Array
Extracted source (around line #186):
183: 
184: <%=
185:     if @tgt_ip_hash.count > 0
186:       raw Seer::visualize(
187:                   @tgt_ip_hash,
188:                   :as => :pie_chart,
189:                   :in_element => 'tgt_pie_chart',

這是課程

class IP_data
  attr_accessor :ip, :count

  def initialize(ip, count)
    @ip = ip
    @count = count
  end
end

您實際上是在發送哈希:

IP_data.new({:ip => t[0],:count => t[1]})

做就是了:

IP_data.new(t[0],t[1])

您仍然需要上一個循環(在循環中刪除了@ tgt_ip_arrat.push),請更改為:

  @tgt_ip_hash.each do |t|
    @tgt_ip_array.push(IP_data.new(t[0],t[1]))
  end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM