that doesn't do what you think it does (take a look at the javascript that is generated)
I wrote about this a few weeks ago: Conditional RJS explained - Space Vatican
but that doesn't seem the best way to do it. What is
the recommended way to do this?
I don't know about the 'recommended' part (your approach doen't seem
'flawed' to me), but RJS let's you test for the presence of a DOM element
using CSS-based selectors.
Assuming you've got an element with an id='test', you might try...
page.select "#test"
page['test'].visual_effect :highlight
end
but that doesn't seem the best way to do it. What is
the recommended way to do this?
I don't know about the 'recommended' part (your approach doen't seem
'flawed' to me), but RJS let's you test for the presence of a DOM
element
using CSS-based selectors.
Assuming you've got an element with an id='test', you might try...
page.select "#test"
page['test'].visual_effect :highlight
end
That won't do much, but
page.select("#test").each {|element| element.visual_effect :highlight}
I don't know about the 'recommended' part (your approach doen't seem
'flawed' to me), but RJS let's you test for the presence of a DOM element
using CSS-based selectors.
Assuming you've got an element with an id='test', you might try...
page.select "#test"
page['test'].visual_effect :highlight
end
Sigh. that will work (and is basically the same as what I wrote) as
long as you add the 'do' that I'm sure you meant to write.
Thanks for the feedback on this guys. It's all been very useful to
know.
It seems like this is quite a common occurrence (the need to check if
an element exists before doing something to it) - it seems strange
that an RJS helper doesn't exist for it - resorting to feeding in JS
using page << seems to bit hackish....
It seems like this is quite a common occurrence (the need to check if
an element exists before doing something to it) - it seems strange
that an RJS helper doesn't exist for it - resorting to feeding in JS
using page << seems to bit hackish....
An RJS helper does exist. The 'select'. Thanks to Fred, we now know it
just needs to be used as he recommends: in a block rather than an 'if then
else' His statement re: using page << wasn't a recommendation; just a 'if
that's how you what to do it, this is the syntax you'll have to use'. I'd
use his earlier (and better tested than mine) recommend solution.
Thanks for the feedback on this guys. It's all been very useful to
know.
It seems like this is quite a common occurrence (the need to check if
an element exists before doing something to it) - it seems strange
that an RJS helper doesn't exist for it - resorting to feeding in JS
using page << seems to bit hackish....
if you read the blog post I linked to there is a plugin with helpers
for this. At a basic level I'd say large amounts of complicated
javascript in rjs isn't really a great idea.