RJS where to put helper method?

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

So no one has any input on this?
I’m sure you all needs it right?

On 7/20/06, Reynard H. [email protected] wrote:

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 :slight_smile:
I was just interested to know if that’s what everyone does.

  • reynard

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.

That’s exactly the behavior I wanted, and it’s already built in. I
should
have read the documentation more thoroughly :slight_smile:
Thanks a lot!

  • reynard

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs