Hi!
I am trying to show devices in my database in a table format and in each
column corresponding to one device im trying to give a ping link which will
ping the device and update the result of ping just below the ping link.
What problem im facing is every time first cell is updated for ping result
of any device. this is clearly a problem Related to div id's , how to
distinguish each cell's div id's.
Kindly have a look at my code :
My view looks like:
My controller looks like:
def show_ping_ip_addr
@ipadd=Ipaddr.find_by_id(params[:ipaddr_id])
if system("ping #{@ipadd.address}")
res="Yes it is connected"
else
res="Host unreachable"
end
logger.error "variable is equal to: #{res}"
render :update do |page|
#logger.error "Got here 2"
page.replace_html 'ping_result', (res || "No Results").to_s
page.show 'ping_result'
page.visual_effect:highlight, 'ping_result', :duration => 0.2
end
end
What problem im facing is every time first cell is updated for ping result
of any device. this is clearly a problem Related to div id's , how to
distinguish each cell's div id's.
The whole point of ids is that they are unique, if they aren't results
are undefined. Just make them unique (eg append the id of the Ipaddr
record). There are even helpers like dom_id, div_for etc...
@ipadd=Ipaddr.find_by_id(params[:ipaddr_id])
devid=@ipadd.dev_id
if system("ping #{@ipadd.address}")
res="Yes it is connected"
else
res="Host unreachable"
end
logger.error "variable is equal to: #{res}"
render_text "ping"+ res.to_s
@ipadd=Ipaddr.find_by_id(params[:ipaddr_id])
devid=@ipadd.dev_id
if system("ping #{@ipadd.address}")
res="Yes it is connected"
else
res="Host unreachable"
end
render :update do |page|
page.replace_html 'ping_result_'+devid.to_s, (res || "No Results").to_s
page.show 'ping_result_'+devid.to_s
page.visual_effect:highlight, 'ping_result_'+devid.to_s, :duration => 0.2
end
end
it is correctly identifying unique ids for divs this time in both controller and view(i checked by putting logger statements around) but i cudnt understand the cause for error.
Please someone have a look at it… and help me out!!
Thanx alot!!!
i tried another way to do it... this time its giving
RJS error(Object Error)
it is correctly identifying unique ids for divs this time
in both controller and view
Perhaps in the controller, but in looking at your view code, I can't help
but wonder about the rendered page. I'd start by taking the rendered page
source (before you try to do any RJS updates on it) and run it through the
W3C validator. That'll tell you real quick if you've got unique id's or
not.