Update div using render:update

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:

<th width="70" scope="col">Status</th>


</tr>

<% @devices.each do |c|%>


Device Name

<%=h c.name%>

   </td>

<td>

<%= javascript_include_tag:defaults%>
<%= link_to_remote “Ping”,:url => {:action =>
‘show_ping_ip_addr’,:ipaddr_id=>Ipaddr.find(:first,:conditions
=>[“dev_id=?”,c.id])} %>

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

Thanx in advance!!


View this message in context:
http://www.nabble.com/Update-div-using-render%3Aupdate-tp17960448p17960448.html
Sent from the RubyOnRails Users mailing list archive at Nabble.com.

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…

Fred

I tried to make the id’s unique through the following way:

view now looks like:

<%= javascript_include_tag:defaults%> <%= link_to_remote "Ping",:update=>"ping_result_#{c.id}",:url => {:action => 'show_ping_ip_addr1',:ipaddr_id=>Ipaddr.find(:first,:conditions =>["dev_id=?",c.id])} %>

and controller:
def show_ping_ip_addr1

  @ipadd=Ipaddr.find_by_id(params[:ipaddr_id])

  [email protected]_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

end

but its not displaying anything!!

On Wed, Jun 18, 2008 at 12:36 PM, Frederick C. <

Hi Supriya,

supriya agarwal wrote:

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.

HTH,
Bill

Hey thanx Bill for replying… I am not sure about your idea… can you
just
elaborate it giving an example.

Supriya

On Wed, Jun 18, 2008 at 7:54 PM, Bill W. [email protected]

Hey i am able to do it… small error in my previous code:

      <%= link_to_remote ("Ping",:update=>"ping_result_#{c.id}",:url 

=>
{:action =>
‘show_ping_ip_addr1’,:ipaddr_id=>Ipaddr.find(:first,:conditions
=>[“dev_id=?”,c.id])}) %>

Thanx!

On Thu, Jun 19, 2008 at 9:49 AM, supriya agarwal
[email protected]

Hi

i tried another way to do it… this time its giving RJS error(Object
Error)

view now looks like:

<%= javascript_include_tag:defaults%> <%= link_to_remote "Ping",:url => {:action => 'show_ping_ip_addr',:ipaddr_id=>Ipaddr.find(:first,:conditions =>["dev_id=?",c.id])} %>
and controller:

def show_ping_ip_addr

  @ipadd=Ipaddr.find_by_id(params[:ipaddr_id])

  [email protected]_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!!!

On Wed, Jun 18, 2008 at 1:05 PM, supriya agarwal
[email protected]