Hi, If I want to have helper method for my rjs, where''s the best place to put it? so for example: --- bla.rjs: page.replace_html ... page.visual_effect ... --- somewhere: (currently I put in application_helper.rb) def replace_with_effect(page) page.replace_html ... page.visual_effect ... end --- bla.rjs: replace_with_effect page and is there a way to define the helper so we don''t have to pass the page into the function everytime? thanks, - reynard -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060720/fad71684/attachment.html
So no one has any input on this? I''m sure you all needs it right? On 7/20/06, Reynard Hilman <reynard.list@gmail.com> wrote:> > Hi, > If I want to have helper method for my rjs, where''s the best place to put > it? > > so for example: > --- bla.rjs: > page.replace_html ... > page.visual_effect ... > > --- somewhere: (currently I put in application_helper.rb) > def replace_with_effect(page) > page.replace_html ... > page.visual_effect ... > end > > --- bla.rjs: > replace_with_effect page > > and is there a way to define the helper so we don''t have to pass the page > into the function everytime? > > thanks, > - reynard >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060723/90f4fe62/attachment.html
On 7/20/06, Reynard Hilman <reynard.list@gmail.com> wrote:> Hi, > If I want to have helper method for my rjs, where''s the best place to put > it? > > so for example: > --- bla.rjs: > page.replace_html ... > page.visual_effect ... > > --- somewhere: (currently I put in application_helper.rb) > def replace_with_effect(page) > page.replace_html ... > page.visual_effect ... > end > > --- bla.rjs: > replace_with_effect page > > and is there a way to define the helper so we don''t have to pass the page > into the function everytime?What is wrong with having to pass page? Otherwise page would have to be global. Peter
thanks for the reply :) I was just interested to know if that''s what everyone does. - reynard> What is wrong with having to pass page? Otherwise page would have to be > global. > > Peter > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060724/30f30678/attachment.html
Actually, methods defined in your helpers are available on the page object. module ApplicationHelper def say_hello page.alert "Hello!" end end Then in an RJS template you can use page.say_hello http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html -Jonathan. On 7/24/06, Reynard Hilman <reynard.list@gmail.com> wrote:> thanks for the reply :) > I was just interested to know if that''s what everyone does. > > - reynard > > > > > What is wrong with having to pass page? Otherwise page would have to be > global. > > > > Peter > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
That''s exactly the behavior I wanted, and it''s already built in. I should have read the documentation more thoroughly :) Thanks a lot! - reynard On 7/24/06, Jonathan Viney <jonathan.viney@gmail.com> wrote:> > Actually, methods defined in your helpers are available on the page > object. > > module ApplicationHelper > def say_hello > page.alert "Hello!" > end > end > > Then in an RJS template you can use page.say_hello > > > http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html > > -Jonathan. > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060724/ef7f5d86/attachment.html