RJS : find the parent's id

Hi,

I have a HTML like this :

....

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

page[“data_1”]

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.select(“user_1”).each{|elt|
elt.select(“p.data_1”).each{|u_elt|
page.replace_html u_elt, “test”
}
}

But it doesn’t work… :frowning:

On 8 Aug 2008, at 13:21, joserwan wrote:

page.select(“user_1”).each{|elt|
elt.select(“p.data_1”).each{|u_elt|
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.

Fred

Found it ! :smiley:

render :update do |page|
page[‘user_1’].down(‘p.data_1’).replace_html “test”
end

It’s not the transcription of the prototype style you told me, but it
works…

I haven’t tried, but
$(‘user_1’).select(‘p.data_1’).each(function(element){ …})
should be
page[‘user_1’].select(‘p.data_1’)…

On Aug 8, 9:21 am, Frederick C. [email protected]