Mikel1
(Mikel)
1
I have an RJS template that looks like this:
page.replace "id_#{@foo.id}", :partial => "row"
But I only want it to execute if "id_#{@foo.id}" is an element on the
current page?
something like:
if page.exists?("id_#{@foo.id}")
page.replace "id_#{@foo.id}", :partial => "row"
end
I have read through every API page that I can find and can't find such
a beast? What would be the best way to do this?
Thanks
Mikel
Duplex
(Duplex)
2
not sure, but try this:
page << "if $('id_#{@foo.id}') {"
page.replace "id_#{@foo.id}", :partial => "row"
page << "}"
you can feed straight Javascripts into the page object with << (as
documented in the API), so i think it *should* work
Mikel1
(Mikel)
3
Thanks for the pointer!
You were almost there, the solution was:
page << "elem = $('id_(#{@foo}');"
page << "if (elem) {"
page.replace "id_(#{@foo}", :partial => "row"
page << "}"
Needed the extra step.
Thanks 
Mikel
Daniel_N
(Daniel N)
4
You shouldn’t need an extra step. Just some brackets.
page << “if( $(’
id_#{@foo.id}') ){”
page.replace “id_#{@foo.id}”, :partial => “row”
page << “}”
That should be the equivalent of what you had.
Daniel