Forum: Ruby on Rails ask net-ping

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Junior J. (Guest)
on 2009-04-02 05:18

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:

require 'net/ping'
include Net

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

    @arr_stat =
    i = 0
    for node in @nodes do

      stat =

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

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

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.
Julian L. (Guest)
on 2009-04-02 05:43
(Received via mailing list)
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 = do |node|
{:ipadd => node.ipadd, :status => ? "online" : "offline"}

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

Learn rails:

On 02/04/2009, at 12:18 PM, Junior Junior wangsa
Junior J. (Guest)
on 2009-04-02 06:47
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??
This topic is locked and can not be replied to.