Hiya, I''m trying to get around the problem of not knowing whether to use insert_html or replace_html as there will be times when I will need to add new elements or replace existing ones. Is there some form of check to see if a DOM element exists on the page? Or can I catch errors so that I know there isn''t an element of a certain name already there? Hope that makes sense, Bex -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You (obviously) can''t do this purely server side, you can however as part of your rjs generate the necessary javascript to test for this. So, in fugly land you can do this page<< "if($(''element_id'')){" page[''element_id''].hide]'' page << "}" However this is a plugin http://www.agilewebdevelopment.com/plugins/rjs_if_unless_blocks that allows you to instead do page.if page[element_id].visible do page[element_id].hide end Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 November 2006 14:27, Becky Franklin wrote:> I''m trying to get around the problem of not knowing whether to use > insert_html or replace_html as there will be times when I will need to > add new elements or replace existing ones. Is there some form of check > to see if a DOM element exists on the page? Or can I catch errors so > that I know there isn''t an element of a certain name already there?There are at least two solutions: 1. Create custom javascript methods, e.g. function create_or_update_element(id, content) { .... } 2. Install js-if-blocks plugin ./script/plugin install svn://rubyforge.org/var/svn/js-if-blocks/trunk/js-if-blocks and then write your RJS code like this: page.if page[my_element_id] do page.replace_html element_id, content page.else page.insert_html :top, parent_id, "<div id=''#{element_id}''>#{content}</div>" end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks so much for the replies. Am I right in thinking that these plugins will work if the element itself isn''t there? I tried: page.if page[''test''] do puts "Working!" page.else puts "Else working!" end Where test does not exist on the page, and I get an error saying If is not defined :os Thanks again for the help! Bex -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 November 2006 16:37, Becky Franklin wrote:> Thanks so much for the replies. Am I right in thinking that these > plugins will work if the element itself isn''t there?1. Actually, those two references are to the same plugin 2. Yes, the condition will work.> I tried: > > page.if page[''test''] do > puts "Working!" > page.else > puts "Else working!" > end"puts" will not work, because, actually, there is no true "if" statement. Those are just methods that generate proper javascript. So, in your case, you should use something like page.alert(''Working!'')> Where test does not exist on the page, and I get an error saying If is > not defined :osAs far as I understand, you haven''t installed plugin yet. The error is because "page.if" method is defined in that plugin and not part of standard Rails distribution. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
>> Where test does not exist on the page, and I get an error saying If is >> not defined :os > As far as I understand, you haven''t installed plugin yet. The error is > because "page.if" method is defined in that plugin and not part of > standard > Rails distribution.Ah I see. I''m working on windows and I wasn''t sure if the plugin had installed or not, as I have no error message when i (from the root of my app) type: ruby script/plugin install svn://rubyforge.org/var/svn/js-if-blocks/trunk/js-if-blocks I can just see it being something stupid I''m doing wrong, but I''m assuming that doesn''t install the plugin? Thanks again! Bex -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 November 2006 18:17, Becky Franklin wrote:> > As far as I understand, you haven''t installed plugin yet. The error is > > because "page.if" method is defined in that plugin and not part of > > standard > > Rails distribution. > > Ah I see. I''m working on windows and I wasn''t sure if the plugin had > installed or not, as I have no error message when i (from the root of my > app) type: ruby script/plugin install > svn://rubyforge.org/var/svn/js-if-blocks/trunk/js-if-blocks > > I can just see it being something stupid I''m doing wrong, but I''m > assuming that doesn''t install the plugin?You can check if you have non-empty js-if-blocks directory under ./vendor/plugins directory. Also, make sure you have restarted you server. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maxim Kulkin wrote:> On 8 November 2006 18:17, Becky Franklin wrote: >> I can just see it being something stupid I''m doing wrong, but I''m >> assuming that doesn''t install the plugin? > You can check if you have non-empty js-if-blocks directory > under ./vendor/plugins directory. > > Also, make sure you have restarted you server.Honestly you have completely solved a massive problem with this plugin! Turned out I had the rails versioning wrong or something so once I fixed that the plugin installed and worked like a dream! Now back to officially loing RJS :D Thanks sooooo much! Bex -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---