# Update div using render:update

**URL:** <https://www.ruby-forum.com/t/update-div-using-render-update/140752>\
**Category:** Rails\
**Created:** [June 18, 2008, 9:03am UTC](https://www.ruby-forum.com/t/update-div-using-render-update/140752 "2008-06-18T09:03:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 18, 2008, 9:03am UTC](https://www.ruby-forum.com/t/update-div-using-render-update/140752/1 "2008-06-18T09:03:40Z")

</div>

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](http://www.nabble.com/Update-div-using-render%3Aupdate-tp17960448p17960448.html)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 18, 2008, 9:07am UTC](https://www.ruby-forum.com/t/update-div-using-render-update/140752/2 "2008-06-18T09:07:13Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 18, 2008, 9:36am UTC](https://www.ruby-forum.com/t/update-div-using-render-update/140752/3 "2008-06-18T09:36:44Z")

</div>

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])

  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

```

end

but its not displaying anything!!

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

---

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 18, 2008, 4:25pm UTC](https://www.ruby-forum.com/t/update-div-using-render-update/140752/4 "2008-06-18T16:25:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 19, 2008, 6:19am UTC](https://www.ruby-forum.com/t/update-div-using-render-update/140752/5 "2008-06-19T06:19:35Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 19, 2008, 7:29am UTC](https://www.ruby-forum.com/t/update-div-using-render-update/140752/6 "2008-06-19T07:29:14Z")

</div>

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  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 18, 2008, 3:30pm UTC](https://www.ruby-forum.com/t/update-div-using-render-update/140752/7 "2008-06-18T15:30:20Z")

</div>

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])

  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!!!

On Wed, Jun 18, 2008 at 1:05 PM, supriya agarwal  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
