7

I have a rails 3.0.5 app and I'm setting up capistrano to use a recipe.

in my config directory I have a file named "database_capistrano.rb" and in my deploy.rb, also in config directory, I have the following line, just in the beginning:

require 'database_capistrano'

But I'm getting:

`require': no such file to load -- capistrano_database (LoadError)

Also try with:

require 'database_capistrano.rb'

And don't work...

How, in Rails 3.0.5, include files in capistrano deploy.rb??

Joao Pereira
  • 2,454
  • 4
  • 27
  • 35

2 Answers2

11

Ok, I manage to find out how this should be done.

Just copied the file to a new sub-directory "deploy", for organization only, and at the beginning of my deploy.rb, added:

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'deploy')

Then, in deploy.rb, just used:

require 'database_capistrano'
Joao Pereira
  • 2,454
  • 4
  • 27
  • 35
  • Thanks, also had this problem and this solved it. Wish I understood the problem in the first place=) – DavveK Aug 12 '11 at 21:52
  • Capistrano recipes want to be required. You have to add the location that you're storing the recipes in to ruby's $LOAD_PATH variable in order to get require to find it. – BeepDog Aug 22 '11 at 00:02
  • 1
    so is the structure app->config->deploy->database_capistrano.rb ? I'm still getting errors about not finding the file. I tried root dir, config dir, deploy dir... – Danny Aug 02 '13 at 22:39
0

For future visitors, I got better results with the answer found in Capistrano: deploy.rb file refactoring

i.e instead of require, use load. As long as that file is a gem in the bundle or a file that requires other gems that are in bundle, this will work.

To be frank, I didn't try the accepted answer, half because it looked a little workaround-ish, and half because I didnt fully understand how to adapt it for my situation

Community
  • 1
  • 1
Karthik T
  • 31,456
  • 5
  • 68
  • 87
  • can you please add link to documentation to load method. – Arnold Roa Apr 17 '17 at 03:19
  • @ArnoldRoa I couldnt find any docs but the method is defined here in Cap 2 https://github.com/capistrano/capistrano/blob/legacy-v2/lib/capistrano/configuration/loading.rb – Karthik T Apr 18 '17 at 04:26