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 ?

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top