Helper in Initializer: Is it possible ?

Hi there,

is there a way in Rails to use helpers in an Initializer ?

If yes, how ?

If no, where else to put the code needed in the Initializer (as well as in views) ? In the application_controller.rb ?

Thanks for any hints! Tom

Tom Ha wrote:

Hi there,

is there a way in Rails to use helpers in an Initializer ?

You should never need to. Helpers are only for generating view code, and you shouldn't be doing that in initializers.

If yes, how ?

If no, where else to put the code needed in the Initializer (as well as in views) ? In the application_controller.rb ?

Thanks for any hints! Tom

What are you trying to achieve?

What are you trying to achieve?

Basically, I put some Rufus scheduler code in the Initializer folder so the scheduler runs fine, even when the hoster needs to reboot the machine for whatever reason and without my knowledge.

The Rufus scheduler includes some .pdf-generating code (amongst other features). The .pdf must display numbers in a special format. And until now, I used helper code to get the numbers into this format, so it would have been convenient to use the same helper within this Rufus scheduler initializer..

Tom Ha wrote:

The .pdf must display numbers in a special format. And until now, I used helper code to get the numbers into this format, so it would have been convenient to use the same helper within this Rufus scheduler initializer..

To my casual eye this seems like something that should go in as a routine a library file and that routine should be called both in your helper and in your initializer. It just needs a small amount of refactoring as your needs have changed.

Bob

Thanks!