# Ask net-ping

**URL:** <https://www.ruby-forum.com/t/ask-net-ping/164514>\
**Category:** Rails\
**Created:** [April 2, 2009, 3:18am UTC](https://www.ruby-forum.com/t/ask-net-ping/164514 "2009-04-02T03:18:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vgenjr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9dc877/32.png) [@vgenjr](https://www.ruby-forum.com/u/vgenjr)\
**Post date:** [April 2, 2009, 3:18am UTC](https://www.ruby-forum.com/t/ask-net-ping/164514/1 "2009-04-02T03:18:15Z")

</div>

hi,

can anybody help me?  
i wanna create a RoR monitoring application for my project.  
i have a database with table named nodes  
in that nodes i have id and ipadd.

here’s my code:  
#nodes\_controller.rb

require ‘net/ping’  
include Net

class NodesController \< ApplicationController  
def index  
@nodes = Node.find(:all)

```
@arr_stat = Array.new
i = 0
for node in @nodes do

  stat = PingExternal.new(node.ipadd)

  @arr_stat[i]['ipadd'] = node.ipadd
  if stat
    @arr_stat[i]['status'] = 'online';
    puts "online"
  else
    @arr_stat[i]['status'] = 'offline';
    puts "offline"
  end
end

respond_to do |format|
  format.html { render :html => @arr_stat }# index.html.erb
  format.xml { render :xml => @nodes }
end

```

end  
##########################

why when i run the code it always says:

You have a nil object when you didn’t expect it!  
You might have expected an instance of ActiveRecord::Base.  
The error occurred while evaluating nil.[]=

please help me solved this.

---

<div class="post-metadata">

**Author:** ![vgenjr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9dc877/32.png) [@vgenjr](https://www.ruby-forum.com/u/vgenjr)\
**Post date:** [April 2, 2009, 3:43am UTC](https://www.ruby-forum.com/t/ask-net-ping/164514/2 "2009-04-02T03:43:28Z")

</div>

Your array is a simple array, but you’re referencing it like its an  
array of hashes.

Also you’re using I like an incrementor, but you never increment it.  
Its not very ruby-like.

Try this:

@arr\_stat = Node.all.map do |node|  
{:ipadd =\> node.ipadd, :status =\>  
PingExternal.new(node.ipadd) ? “online” : “offline”}  
end

However, depending on what you want to do with this data later, this  
may be a bad implentation.

Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Learn rails: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)

On 02/04/2009, at 12:18 PM, Junior Junior wangsa  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![vgenjr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9dc877/32.png) [@vgenjr](https://www.ruby-forum.com/u/vgenjr)\
**Post date:** [April 2, 2009, 4:47am UTC](https://www.ruby-forum.com/t/ask-net-ping/164514/3 "2009-04-02T04:47:43Z")

</div>

Thanks Julian

i already try it…  
and it works…

how i call and show the data in my html.erb??

can u show me how??
