Hello Everybody, To keep my code dry, I want to use a partial rjs from within another rjs. Is this possible and if so, how should I do this. If it''s not possible, is there a way to cut up the code which I want to use in a call with rjs and How can this be done Thanx in advance, Jeroen van Doorn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jeroen van Doorn wrote:> Hello Everybody, > > To keep my code dry, I want to use a partial rjs from within another > rjs. Is this possible and if so, how should I do this. > If it''s not possible, is there a way to cut up the code which I want to > use in a call with rjs and How can this be done > > Thanx in advance, > Jeroen van DoornRJS is pure ruby code, so I would expect it can be done, but I''m a little confused as to exactly what you''re attempting - can you put up a specific code example of how you think it should/might work? Will go a long way towards understanding your intent. c. -- 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 -~----------~----~----~----~------~----~------~--~---
Cayce Balara schreef:> Jeroen van Doorn wrote: > >> Hello Everybody, >> >> To keep my code dry, I want to use a partial rjs from within another >> rjs. Is this possible and if so, how should I do this. >> If it''s not possible, is there a way to cut up the code which I want to >> use in a call with rjs and How can this be done >> >> Thanx in advance, >> Jeroen van Doorn >> > > RJS is pure ruby code, so I would expect it can be done, but I''m a > little confused as to exactly what you''re attempting - can you put up a > specific code example of how you think it should/might work? Will go a > long way towards understanding your intent. > > c. > >Hi C, What I want is something like the following == _base_code.rjs page.update "base", "this is the base rjs" # a lot more code == method1.rjs page.update "example1", "SomeValue1" # a lot more code render :partial => "base_code", :file => "_base_code.rjs" == method2.rjs page.update "example2", "SomeValue2" # a lot more code render :partial => "base_code", :file => "_base_code.rjs" The above is what I tried in a test app, but it doesn''t work. The reason is that I have multiple function which call "base" with ajax after they are handled themselves. (these functions are ajax functions themselves). I also need to call "base" on it''s own sometimes. But what I don''t want anymore is the extra ajax call to "base" from the other functions. I want the needed rjs send in one call. Hope there''s another solution or that I''m making some stupid mistake ;) Regards, Jeroen van Doorn --~--~---------~--~----~------------~-------~--~----~ 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 Nov 10, 2006, at 8:59 AM, Jeroen van Doorn wrote:> > Cayce Balara schreef: >> Jeroen van Doorn wrote: >> >>> Hello Everybody, >>> >>> To keep my code dry, I want to use a partial rjs from within another >>> rjs. Is this possible and if so, how should I do this. >>> If it''s not possible, is there a way to cut up the code which I >>> want to >>> use in a call with rjs and How can this be done >>> >>> Thanx in advance, >>> Jeroen van Doorn >>> >> >> RJS is pure ruby code, so I would expect it can be done, but I''m a >> little confused as to exactly what you''re attempting - can you put >> up a >> specific code example of how you think it should/might work? Will >> go a >> long way towards understanding your intent. >> >> c. >> >> > Hi C, > > What I want is something like the following > > == _base_code.rjs > page.update "base", "this is the base rjs" > # a lot more code > > == method1.rjs > > page.update "example1", "SomeValue1" > # a lot more code > render :partial => "base_code", :file => "_base_code.rjs" > > == method2.rjs > > page.update "example2", "SomeValue2" > # a lot more code > render :partial => "base_code", :file => "_base_code.rjs" > > The above is what I tried in a test app, but it doesn''t work. The > reason > is that I have multiple function which call "base" with ajax after > they > are handled themselves. (these functions are ajax functions > themselves). > I also need to call "base" on it''s own sometimes. But what I don''t > want > anymore is the extra ajax call to "base" from the other functions. I > want the needed rjs send in one call. Hope there''s another solution or > that I''m making some > stupid mistake ;)I think you want to use a technique I learned yesterday (thanks to Dave Hoover!) which relies on the use of nested singleton methods. It would look something like this using your example as a guide: def some_action # some model code or other setup code # the rjs stuff update_page do |page| page.method1 page.method2(some_arg) end end def update_page render :update do |page| def page.method1 replace_html "div1", :partial => "some_html" # might need :locals hash here end def page.method2(some_arg) replace_html "div2_#{some_arg}", :partial => "some_html" # again, you might need to explicitly # pass in some local variables depending # on how you setup your partial end def page.base_code # some more code end yield(page) end end Apparently there is a special context setup when you do the "render :update do" call, so calling out to external methods upsets that context. Using the singleton methods keeps the context pure and will output the correct rjs. This keeps your code looking pretty clean. I hope I didn''t completely miss the point of your question... cr --~--~---------~--~----~------------~-------~--~----~ 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 Nov 10, 2006, at 9:40 AM, cremes.devlist-ee4meeAH724@public.gmane.org wrote:> > > On Nov 10, 2006, at 8:59 AM, Jeroen van Doorn wrote: > >> >> Cayce Balara schreef: >>> Jeroen van Doorn wrote: >>> >>>> Hello Everybody, >>>> >>>> To keep my code dry, I want to use a partial rjs from within >>>> another >>>> rjs. Is this possible and if so, how should I do this. >>>> If it''s not possible, is there a way to cut up the code which I >>>> want to >>>> use in a call with rjs and How can this be done >>>> >>>> Thanx in advance, >>>> Jeroen van Doorn >>>> >>> >>> RJS is pure ruby code, so I would expect it can be done, but I''m a >>> little confused as to exactly what you''re attempting - can you put >>> up a >>> specific code example of how you think it should/might work? Will >>> go a >>> long way towards understanding your intent. >>> >>> c. >>> >>> >> Hi C, >> >> What I want is something like the following >> >> == _base_code.rjs >> page.update "base", "this is the base rjs" >> # a lot more code >> >> == method1.rjs >> >> page.update "example1", "SomeValue1" >> # a lot more code >> render :partial => "base_code", :file => "_base_code.rjs" >> >> == method2.rjs >> >> page.update "example2", "SomeValue2" >> # a lot more code >> render :partial => "base_code", :file => "_base_code.rjs" >> >> The above is what I tried in a test app, but it doesn''t work. The >> reason >> is that I have multiple function which call "base" with ajax after >> they >> are handled themselves. (these functions are ajax functions >> themselves). >> I also need to call "base" on it''s own sometimes. But what I don''t >> want >> anymore is the extra ajax call to "base" from the other functions. I >> want the needed rjs send in one call. Hope there''s another >> solution or >> that I''m making some >> stupid mistake ;)Oops, I forgot the call to #base_code in my example. Try this. def some_action # some model code or other setup code # the rjs stuff update_page do |page| page.method1 page.method2(some_arg) end end def update_page render :update do |page| def page.method1 replace_html "div1", :partial => "some_html" # might need :locals hash here base_code # call the singleton object in this context end def page.method2(some_arg) replace_html "div2_#{some_arg}", :partial => "some_html" # again, you might need to explicitly # pass in some local variables depending # on how you setup your partial base_code end def page.base_code # some more code end yield(page) end 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 -~----------~----~----~----~------~----~------~--~---
cremes.devlist-ee4meeAH724@public.gmane.org schreef:> On Nov 10, 2006, at 9:40 AM, cremes.devlist-ee4meeAH724@public.gmane.org wrote: > > >> On Nov 10, 2006, at 8:59 AM, Jeroen van Doorn wrote: >> >> >>> Cayce Balara schreef: >>> >>>> Jeroen van Doorn wrote: >>>> >>>> >>>>> Hello Everybody, >>>>> >>>>> To keep my code dry, I want to use a partial rjs from within >>>>> another >>>>> rjs. Is this possible and if so, how should I do this. >>>>> If it''s not possible, is there a way to cut up the code which I >>>>> want to >>>>> use in a call with rjs and How can this be done >>>>> >>>>> Thanx in advance, >>>>> Jeroen van Doorn >>>>> >>>>> >>>> RJS is pure ruby code, so I would expect it can be done, but I''m a >>>> little confused as to exactly what you''re attempting - can you put >>>> up a >>>> specific code example of how you think it should/might work? Will >>>> go a >>>> long way towards understanding your intent. >>>> >>>> c. >>>> >>>> >>>> >>> Hi C, >>> >>> What I want is something like the following >>> >>> == _base_code.rjs >>> page.update "base", "this is the base rjs" >>> # a lot more code >>> >>> == method1.rjs >>> >>> page.update "example1", "SomeValue1" >>> # a lot more code >>> render :partial => "base_code", :file => "_base_code.rjs" >>> >>> == method2.rjs >>> >>> page.update "example2", "SomeValue2" >>> # a lot more code >>> render :partial => "base_code", :file => "_base_code.rjs" >>> >>> The above is what I tried in a test app, but it doesn''t work. The >>> reason >>> is that I have multiple function which call "base" with ajax after >>> they >>> are handled themselves. (these functions are ajax functions >>> themselves). >>> I also need to call "base" on it''s own sometimes. But what I don''t >>> want >>> anymore is the extra ajax call to "base" from the other functions. I >>> want the needed rjs send in one call. Hope there''s another >>> solution or >>> that I''m making some >>> stupid mistake ;) >>> > > Oops, I forgot the call to #base_code in my example. Try this. > > > def some_action > # some model code or other setup code > > # the rjs stuff > update_page do |page| > page.method1 > page.method2(some_arg) > end > end > > def update_page > render :update do |page| > def page.method1 > replace_html "div1", > :partial => "some_html" > # might need :locals hash here > base_code # call the singleton object in this context > end > > def page.method2(some_arg) > replace_html "div2_#{some_arg}", > :partial => "some_html" > # again, you might need to explicitly > # pass in some local variables depending > # on how you setup your partial > base_code > end > > def page.base_code > # some more code > end > > yield(page) > end > end > > > > > > > >Hi CR, Sorry for the late reply (I was moving to another place) ... Thanxs, I''ll try this ... do you have any idea if it''s possible to put the rjs code in seperate files? Regards and thanxs again, Jeroen --~--~---------~--~----~------------~-------~--~----~ 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 Nov 20, 2006, at 1:39 AM, Jeroen van Doorn wrote:>> (snip) > Hi CR, > > Sorry for the late reply (I was moving to another place) ... Thanxs, > I''ll try this ... do you have any idea if it''s possible to put the rjs > code in seperate files?Not really sure. Try running the code as given in a single file and then experiment with breaking it up. I imagine you can break some of it up except for the singleton methods. cr --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---