Let me start by saying there is a lot of context in your question that
I don't fully understand, but I will do my best to point you in the
direction I think you want to go.
1. This issue is not attributable to nginx/passenger but rather the
Rails environment.
- While using Webrick you are running in "development" mode which
means Rails will use Rails.root/config/environments/development.rb on
startup to load the environment. The default development.rb file has
a line "config.cache_classes = false" which tells the application to
not cache the class definition because you are in "development" and
want to be able to change the class definitions while the server is
running.
- When you deployed to passenger the default environment is production
(it assumes you are deploying for production because nginx/passenger
is often used for production). Your production.rb file sets
"config.cache_classes" to true which then loads the models.
as you can see in this snippet from the rails source, if cache_classes
== true and it is not a rake task the classes are eager loaded (or
cached).
module Rails
class Application
module Finisher
# ...
initializer :eager_load! do
if config.cache_classes && !$rails_rake_task
ActiveSupport.run_load_hooks(:before_eager_load, self)
eager_load!
end
end
# ...
end
end
end
2. I think we are missing some context about which parts of the
solution outlined in the link you provided were followed. (I looked
at the link and the solution and if you did all of the steps [remove
active_record railtie, remove AR from Gemfile] then it wouldn't work
in any environment)
- If you remove the active_record gem from the Gemfile then you can't
call in AR to establish the connection when a user authenticate. If
you remove the railtie then you won't have access to it from within
rails.
- I think you want to leave those file included and just override the
default behavior of rails when initiating a request. (Is there any
model shared between users? if so you should override AR conn on that
model. Do you have a finite set of DB's to connect to? If so you may
want to create a connection pool-pool data structure in memory with
active connections to each so each request does not have the overhead
of establishing a new connection)
Overall you can "fix" this by setting cache_classes, but depending on
volume/performance that really isn't a long term solution. You should
think about how you want to manage this long term and move in that
direction, the possibilities are numerous as this type of database
strategy has many variables and constraints to be thought through.
The guys as Phusion can take care of the Server side (and they do
great), but can't make the architectural decision.
All the luck,
bsd
On Jan 14, 6:23 am, Kira Corina <
kira.cor...@gmail.com> wrote:
> Hi guys,
>
> I have multiple legacy DBs and a Rails app.
>
> Initially there is no any DB connection in the app.
> (I turn ActiveRecord off using these instructions:
http://stackoverflow.com/questions/2212709/remove-activerecord-in-rai...)