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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thorsten
2007-Jul-01 09:08 UTC
Re: How to conditionally replace an element using RJS template
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 On 1 Jul., 09:22, Mikel <raasdnil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mikel
2007-Jul-01 09:42 UTC
Re: How to conditionally replace an element using RJS template
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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Daniel N
2007-Jul-01 11:29 UTC
Re: How to conditionally replace an element using RJS template
On 7/1/07, Mikel <raasdnil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > 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 :) > > MikelYou shouldn''t need an extra step. Just some brackets. page << "if( $(''id_#{@foo.id <id_#%7B-sW51h6flRGM@public.gmane.org>}'') ){" page.replace "id_#{@foo.id <id_#%7B-sW51h6flRGM@public.gmane.org>}", :partial => "row" page << "}" That should be the equivalent of what you had. Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---