RJS : find the parent's id


I have a HTML like this :

<div id="user_1">
    <p class = "data_1"></p>
    <p class = "data_2"></p>
<div id="user_2">

In my controller, I have a "update_data" method, called every x
seconds from a periodical_call_remote :

I want to take all the elements having the class "data_1", and replace
their html with :

render :partial => data_1, :local => {:user_id => user_id}, where
user_id is the id of the parent of p.data_1

But I didn't find how to to catch the parents id of p.data_1 !

Does someone have an idea ?

Thank you


Thank you for your response but :

In this case, it will look for the element wich have the id "data_1".

And if I have 50 users, I'll have 50 "data_1" classes.

I would like a way to find the css equivalent of "#user_1 .data_1"

I tried :

             page.replace_html u_elt, "test"

I'm coming into this half way, but that selector you've got there is
wrong (that would select tags called user_1)

In pure prototype,

$('user_1').select('p.data_1').each(function(element){ ...})

There are limits to what rjs can map to javascript, something like

page.select('#user_1 p.data_1').each {|elt| elt.update 'test'}

would probably do it, but I'd probably stop fighting rjs and write it
by hand.


Found it ! :smiley:

render :update do |page|
     page['user_1'].down('p.data_1').replace_html "test"

It's not the transcription of the prototype style you told me, but it

I haven't tried, but
$('user_1').select('p.data_1').each(function(element){ ...})
should be