5

I have read previous threads on this topic, but the solutions I've found there have not solved my problem. I have a rails 3.2.9 application that does not do database access - it uses an HTTP Rest protocol to another application to access persistent data. The app runs OK in a local test environment with "rails server" using WEbrick, but fails to run with Nginx/Passenger with the error "* Exception LoadError in application (Please install the sqlite3 adapter: gem install activerecord-sqlite3-adapter (sqlite3 is not part of the bundle. Add it to Gemfile.))". From the stack trace it would appear that ActiveRecord wants to eagerly establish a database connection in code that executes prior to the request being processed. I have tried to follow the instructions to remove ActiveRecord from my dependencies with no luck. I generated with --skip-activerecord, which produced an application.rb like this as expected:

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

# Pick the frameworks you want:
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"

There are no references to activerecord or active_record anywhere in my application except in the gemlock file created by bundler, in comments and in readme. Bundler reports ActiveRecord as a dependency, and 'bundle viz' reports rails itself as being the gem requiring ActiveRecord. Any suggestions or advice would be most welcome.

In response to eric's question, here is my Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.9'

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
Martin Nally
  • 105
  • 1
  • 6
  • 1
    What do you have in your gemfile? – Eric K Dec 17 '12 at 21:52
  • thanks for the quick response, Eric. I updated the question to add the information you requested – Martin Nally Dec 17 '12 at 23:55
  • do you have a `database.yml`? What's in it? did you see this answer? http://stackoverflow.com/a/9139040/376680 – mraaroncruz Dec 18 '12 at 00:10
  • Thanks for the response. I do not have a database.yml file. I did see the answer you reference - notice the comment by user341458 saying that (s)he also still sees activerecord included as a dependency. In my case this seems to be the likely root cause of my nginx/passenger failure. As an aside, you can reproduce my problem without my files using these steps: – Martin Nally Dec 18 '12 at 01:47
  • As an aside, you can reproduce my problem without my files using these steps: 1) "rails new demo_app --skip-activerecord" 2) witness that the bundle install includes activerecord 3) "rails generate scaffold User name:string email:string" 4) write a dummy class User that just keeps a hash of users in memory 5) verify it works locally 6) verify it fails with nginx/passenger – Martin Nally Dec 18 '12 at 01:59
  • `bundle install` includes activerecord because it is a dependency of rails [here](https://github.com/rails/rails/blob/master/rails.gemspec#L25). – mraaroncruz Dec 18 '12 at 14:09
  • have you tried to run `RAILS_ENV=production bundle exec rails server` locally? What happens? I think it has to be something either with bundler on your server or your `config/environments/production.rb` file. – mraaroncruz Dec 18 '12 at 14:13
  • Thanks for your continued help. I ran "bundle install --deployment" locally and the application now fails locally in the same way, so apparently it was "bundle install --deployment" that changed the behavior, not the passenger environment. I'm guessing I might be able to get around this by including sqlite3 even though I don't use it, although this feels like a kludge. – Martin Nally Dec 19 '12 at 01:41

1 Answers1

3

As you have discovered Rails itself has ActiveRecord listed as a dependency in it's Gemspec. The setup you have archived so far is the standard way of removeing ActiveRecord from Rails. If you really want to go further and also remove the gem you will, most likely, have to fork the Rails gem and remove the dependency in it's Gemspec.

It might be that simple, but you might also find that there is additional glue code in Rails to tie ActiveRecord in and you will have to remove that as well. All in all I'm wondering if its worth it.

If you don't need ActiveRecord you have already prevented it from effectively loading. Some parts might still load, but most of it wont. The win in memory footprint/performance against the time you will spend removing a core Rails feature makes me wonder if you are not looking at the wrong framework for your needs?

If you have requirements that are so tight that Rails is still to heavy you should probably look at Sinatra or similar instead. You could also stick with Rails and do a custom Rack middleware stack to keep just the parts of the call stack that you need.

I hope this gave you some guidance to, if not a viably solution, some alternatives to fullfil the higher concerns, since there is no reason in it self to remove the ActiveRecord gem.