Does Rails 2.0 *require* a db? Sure seems that way

I do a number of protoype apps in Rails and up until 2.0 I haven’t had
any issues running them without a DB.

I’m running a naked Rails 2.0 app with only a few views, no ActiveRecord
models and using the default session store (zee Cookied one):


Processing EventsController#index (for 127.0.0.1 at 2007-11-26 20:07:29)
[GET]
Session ID:
BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D–b922ebe60d92900bcef0795360cd
Parameters: {“action”=>“index”, “controller”=>“events”}

Mysql::Error (#42000Incorrect database name
‘prototype.com_development’):
/vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:523:in
read' /vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:153:inreal_connect’
/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:471:in
connect' /vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:165:ininitialize’
/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:88:in
new' /vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:88:inmysql_connection’
/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:291:in
send' /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:291:inconnection=’
/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:259:in
retrieve_connection' /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:inconnection’
/vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in
cache' /vendor/rails/actionpack/lib/action_controller/caching.rb:668:inperform_action’
/vendor/rails/actionpack/lib/action_controller/base.rb:513:in send' /vendor/rails/actionpack/lib/action_controller/base.rb:513:inprocess_without_filters’
/vendor/rails/actionpack/lib/action_controller/filters.rb:685:in
process_without_session_management_support' /vendor/rails/actionpack/lib/action_controller/session_management.rb:123:inprocess’
/vendor/rails/actionpack/lib/action_controller/base.rb:377:in
process' /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:171:inhandle_request’
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:115:in
dispatch' /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:126:indispatch_cgi’
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:9:in
dispatch' c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:inprocess’
c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in
synchronize' c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:inprocess’
c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in
process_client' c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:ineach’
c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in
process_client' c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:inrun’
c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in
initialize' c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:innew’
c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in
run' c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:ininitialize’
c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in
new' c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:inrun’
c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in
run' c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:ineach’
c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in
run' c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:inrun’
c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in
run' c:/dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243 /vendor/rails/activesupport/lib/active_support/dependencies.rb:489:inload’
/vendor/rails/activesupport/lib/active_support/dependencies.rb:489:in
load' /vendor/rails/activesupport/lib/active_support/dependencies.rb:342:innew_constants_in’
/vendor/rails/activesupport/lib/active_support/dependencies.rb:489:in
load' /vendor/rails/railties/lib/commands/servers/mongrel.rb:64 c:/dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
c:/dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
require' /vendor/rails/activesupport/lib/active_support/dependencies.rb:496:inrequire’
/vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in
new_constants_in' /vendor/rails/activesupport/lib/active_support/dependencies.rb:496:inrequire’
/vendor/rails/railties/lib/commands/server.rb:39
c:/dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' c:/dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
script/server:3


WTF Mates? Here’s the oh so exciting environment.rb:

– environment.rb –

Specifies gem version of Rails to use when vendor/rails is not present

#RAILS_GEM_VERSION = ‘1.2.5’ unless defined? RAILS_GEM_VERSION

Bootstrap the Rails environment, frameworks, and default configuration

require File.join(File.dirname(FILE), ‘boot’)

Rails::Initializer.run do |config|
config.action_controller.session = { :session_key => “_prototype”,
:secret => “not so secretive” }
end


Anyone have any ideas on why it needs a db? Thanks

Rich

Nope. Just do this in your environment.rb:

config.frameworks -=
[:active_record, :action_web_service, :action_mailer]

All will then be well (or, at least it works for me :slight_smile:

Steve R. wrote:

Nope. Just do this in your environment.rb:

config.frameworks -=
[:active_record, :action_web_service, :action_mailer]

All will then be well (or, at least it works for me :slight_smile:

That works and seems like a good practice that I’ll continue. Still
confused in the silent change as this wasn’t required pre-2.0 if you
simply never used those frameworks. Moving on though.

Thanks for the help, Steve.

On 27 Nov 2007, at 05:00, Richard W. wrote:

Steve R. wrote:

Nope. Just do this in your environment.rb:

config.frameworks -=
[:active_record, :action_web_service, :action_mailer]

All will then be well (or, at least it works for me :slight_smile:

I’ve got a small app which doesn’t use active_record

I did have to comment out #require ‘test_help’ in my test_helper.rb
(since that requires fixtures, which in turn needs ActiveRecord) (and
then copied into my test_helper.rb the bits from test_help which were
relevant.

I also had to edit environment.rb to add

module Rails
class Initializer
def load_observers
if configuration.frameworks.include?(:active_record)
ActiveRecord::Base.instantiate_observers
end
end
end
end

Fred