Moe Zecko wrote:
how is it possible to find out, if an object (div) exists
in the DOM via RJS? i am trying to find out if an
object exists before applying a visual action on it, so
Interesting question. I'll start by saying I still consider myself pretty new to Rails, js, and Ajax. I was out of hands-on development for 15 years and have only been working with Rails for a little over a year now. So I either don't understand your question, or your context, or both More below.
i am wondering why nobody seems to have had
this problem allready. how do you guys prevent
sort of safe RJS calls?
I think Rails probably eliminates most of the need for the kind of thing you're asking about. In general, I know that something exists in the DOM because I put it there. 99.9% of the time, the page content in a Rails app is rendered dynamically. If it's on the page, it's there because I just put it there; typically as a result of something that's stored in the database. In your case, it looks like you're probably doing or could be doing a find on your Person model. If the find returns a result, then there's a DOM element. If the situation were one where the Person record could exist in the database but I might or might not have rendered a DOM element, I'd either put a field in the database or use a session variable to track it, depending on the situation.