Question

i wrote some helper methods for my application like this

module Magick
  class Draw
    def qrcode(qrcode, left_corner, top_corner, right_corner, bottom_corner)
      size = qrcode.modules.length
      width = right_corner - left_corner
      height = bottom_corner - top_corner
      wset = width.to_f / size
      hset = height.to_f / size
...............

Where to place such code in rails ?

Was it helpful?

Solution

A common and easy way to load those patches is to create a file inside your ./config/initializers directory (ie: rmagick.rb) and put your code in this file.

All files in this directory are loaded and executed on environment startup.

You could also create a new file with your code in the lib/ directory (ie: rmagick_draw.rb) and add this line in ./config/application.rb:

config.autoload_paths += %W(#{config.root}/lib)

And then require the file anywhere you need it.

OTHER TIPS

You can put such files into app\classes directory. All classes from this directory are available by default in Rails3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top