2

I have been trying to set up my work environment on a new computer (ruby 1.9.3.p0 and rails 3.2.6) for the last two days and I keep getting the following error when I try to run rails server or rails console:

application.rb:7:in `require': cannot load such file -- acts_as_loggable/acts_as_loggable (LoadError)

This is what my application.rb looks like:

require File.expand_path('../boot', __FILE__)

require 'acts_as_loggable/acts_as_loggable'
require 'acts_as_abusable/acts_as_abusable'
require 'acts_as_luba/acts_as_luba'


module MyProgram
  class Application < Rails::Application
    config.active_record.schema_format = :ruby

    # Custom directories with classes and modules you want to be autoloadable.
    config.autoload_paths += %W(#{config.root}/lib/)
    config.autoload_paths += %W(#{config.root}/app/models/game_mechanics)
    config.autoload_paths += Dir["#{config.root}/app/admin/"]
    config.autoload_paths += Dir["#{config.root}/app/models/"]
    config.active_record.pluralize_table_names = true
    config.action_view.sanitized_allowed_attributes = ['data-link']

My acts_as_loggable.rb file is located in lib/acts_as_loggable. All my other files load okay, except for the 3 that I left in my application.rb code sample.

If I hardcode the path/directory (see below), my app works.

require './lib/acts_as_loggable/acts_as_loggable'
require './lib/acts_as_abusable/acts_as_abusable'
require './lib/acts_as_luba/acts_as_luba'

Does anyone have any clue what is happening and how I can get my app to work without the hardcoded paths?

Thanks.

Huy
  • 10,806
  • 13
  • 55
  • 99
  • The `lib` directory is not in your `$LOAD_PATH`. Why do you need the explicit `require`? Rails auto loading isn't working? – Renato Zannon Oct 03 '12 at 02:30
  • @RenatoZannon Yeah, it doesn't work without require. How do I add lib directory to my $LOAD_PATH? – Huy Oct 03 '12 at 05:06
  • 1
    @RenatoZannon It looks like Rails 3 no longer support auto loading per http://stackoverflow.com/questions/3356742/best-way-to-load-module-class-from-lib-folder-in-rails-3 – Huy Oct 03 '12 at 05:58
  • have you tried to place the requires in a initializer? Maybe rails adds the lib directory to the $LOAD_PATH itself in later stages of the boot. – Renato Zannon Oct 03 '12 at 10:44
  • @RenatoZannon I am trying to avoid changing the file as it is a collaborative project and I don't want to break the app for others. I am going to try and figure out a way to have my system/environment point to the correct folder. – Huy Oct 05 '12 at 16:54
  • The change I meant would not break the application for other people. Please take a look at [the documentation](http://guides.rubyonrails.org/configuring.html#using-initializer-files). – Renato Zannon Oct 05 '12 at 23:17

1 Answers1

2

Your require is before config.autoload_path.

iouri
  • 2,919
  • 1
  • 14
  • 11
  • 5
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – wattostudios Oct 03 '12 at 02:36
  • it's not a critique or request for clarification. It is an answer in a form of a question. – iouri Oct 03 '12 at 02:41