0

If I do something simple like

class Object
  def itworks
    "hoorah"
  end
end

and add this to lib/ I can't see any effect in the rails console. i.e "".itworks gives a method missing. Where is the proper place to add things like this.

npiv
  • 1,837
  • 15
  • 24

3 Answers3

2

You'll need to require it from somewhere that is loaded in your Rails app. A good place for this could be in config/application.rb if you want it to be used in all your configurations:

require "lib/my_helpers"
robbrit
  • 17,560
  • 4
  • 48
  • 68
2

the very same question was asked today; you need to load everything in lib.

What is the best way to load files from the lib folder that add methods to ~existing~ classes in Rails 3?

Be sure to understand the difference between require and autoload

Community
  • 1
  • 1
apneadiving
  • 114,565
  • 26
  • 219
  • 213
1

you can put this file in config\initializers, rails will load it in any environment.

Naren Sisodiya
  • 7,158
  • 2
  • 24
  • 35