0

I have a controller which wish to include a file in another folder, how do I do that? I am using Ruby 1.9.2 and Rails 3.2.6. Thanks

Controller file is in

/project/app/controllers/examples_controller.rb

and the required file is in

/project/example_folder/example.rb
revolver
  • 2,385
  • 5
  • 24
  • 40

4 Answers4

2
require File.join(Rails.root, "example_folder", "example")

assuming /projects/ is your rails application root folder

Erez Rabih
  • 15,562
  • 3
  • 47
  • 64
0

according to here

more info here Why does Ruby 1.9.2 remove "." from LOAD_PATH, and what's the alternative?

requie_relative '../../example_folder/example.rb'
Community
  • 1
  • 1
wizztjh
  • 6,979
  • 6
  • 58
  • 92
0

You can auto load custom directories with classes and modules you want to be.

So you can Edit config/application.rb

# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W(#{config.root}/example_folder)
Shamith c
  • 3,719
  • 3
  • 25
  • 33
0

It would be something like this:

require "#{Rails.root}/example_folder/example.rb"

just before the declaration of your controller.

Gawyn
  • 1,156
  • 1
  • 10
  • 21