How to disable ORM in Rails 3

Is there any way to prevent Rails 3 from using an ORM? In Rails 2, it used to have a description in environments.rb explaining how to do that.

In Rails 3, is there any way to tell it to not use any database? I was trying to make some benchmarks from situations that don't require a database...

Thanks in advance,

Rodrigo.

rails new myapp --skip-active-record

:smiley:

Yehuda Katz Architect | Engine Yard (ph) 718.877.1325

Thanks, Yehuda.

Shouldn't this be added to rails new generator? I run rails new --help before asking here. Here is the result:

Maybe the option isn't in the docs because it doesn't exist on Rails 3 beta 4... This command-line didn't work for me...

Whoops! --skip-activerecord Yehuda Katz Architect | Engine Yard (ph) 718.877.1325

Good try, but I've tested it before sending the message too :wink:

Should be --skip-active-record, I'll revise that before RC together with the output of --help.

It's -O or --skip-activerecord

rails new --help Usage:   rails new APP_PATH [options]

Options:   -d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db)                              # Default: sqlite3   -J, [--skip-prototype] # Skip Prototype files   -T, [--skip-testunit] # Skip TestUnit files       [--dev] # Setup the application with Gemfile pointing to your Rails checkout   -G, [--skip-git] # Skip Git ignores and keeps   -m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL).   -b, [--builder=BUILDER] # Path to an application builder (can be a filesystem path or URL)       [--edge] # Setup the application with Gemfile pointing to Rails repository   -r, [--ruby=PATH] # Path to the Ruby binary of your choice                              # Default: /usr/bin/ruby       [--skip-gemfile] # Don't create a Gemfile   -O, [--skip-activerecord] # Skip ActiveRecord files

Runtime options:   -p, [--pretend] # Run but do not make any changes   -s, [--skip] # Skip files that already exist   -q, [--quiet] # Supress status output   -f, [--force] # Overwrite files that already exist

Rails options:   -h, [--help] # Show this help message and quit   -v, [--version] # Show Rails version number and quit

Description:     The 'rails new' command creates a new Rails application with a default     directory structure and configuration at the path you specify.

Example:     rails new ~/Code/Ruby/weblog

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.     See the README in the newly created application to get going.

Rodrigo, try Rails master.

Cheers, Santiago.

But it shouldn't.

Ok, Santiago, thanks.

Actually, I'm just doing some benchmark tests and I'm not that worried at the moment about this. I remember reading somewhere it was possible for not using an ORM in Rails 3 too but wasn't finding how on documentation. I'm just glad this is already solved on Rails master, needing maybe only a change in the option name from --skip-activerecord to --skip-active-record as Xavier noted. I don't really care about the option name, but I'm glad this is solved since sometime I might need setting up a Rails 3 application without any databases or without ActiveRecord.

For my benchmark tests it is just easier for me to install the activerecord-jdbcsqlite3-adapter gem.

Thank you very much,

Rodrigo.

This may be unrelated but I am curious and wondered if someone could clear something up for me. With the options I understand what is between the brackets are optional, but what does the first flag signify? For example; -T [--skip-testunit]. I know I would type rails new myapp --skip-testunit , so I am a little confused as to what the - T is.

This may be unrelated but I am curious and wondered if someone could clear something up for me. With the options I understand what is between the brackets are optional, but what does the first flag signify? For example; -T [--skip-testunit]. I know I would type rails new myapp --skip-testunit , so I am a little confused as to what the - T is.

what's in the brackets is an optional syntax for the first flag; i.e. you can do

  new myapp --skip-testunit

is the same as

  new myapp -T

Mm, it's good topic, as "how to use help"

Done, --skip-testunit has also been renamed to --skip-test-unit:

http://github.com/rails/rails/commit/92669b8320a45e3f0497bfb83c0c8e55d515be0c

Great! Maybe there should be some explanations on how to disable ORM after the project is created or how to enable ActiveRecord after the project has been created with --skip-active-record. Sometimes, one may start developing the UI and later then start using an ORM.

It used to be explained how to disable ActiveRecord in Rails 2 environment.rb.

Or maybe it is already done. It has been a while from the last time I used Rails master...

I've just tried to, but couldn't test it:

$ rvm gemset use default@rails-master --create $ git pull $ bin/rails --help

Thor is not available. If you ran this command from a git checkout of Rails, please make sure thor is installed, and run this command as `ruby /path/to/rails new myapp --dev`

Installing Thor wasn't enough for changing this message. Then, I guessed I should try "bundle install". But it didn't work too:

$ gem install thor $ gem install bundler $ bundle install

/home/rodrigo/src/git/rails/Gemfile:22:in `evaluate': undefined method `platforms' for #<Bundler::Dsl:0x7f470583e4f8> (NoMethodError)          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/lib/bundler/definition.rb:12:in `from_gemfile'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/lib/bundler.rb:114:in `definition'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/lib/bundler/cli.rb:91:in `install'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/lib/bundler/vendor/thor/task.rb:33:in `send'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/lib/bundler/vendor/thor/task.rb:33:in `run'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/lib/bundler/vendor/thor/invocation.rb:109:in `invoke'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/lib/bundler/vendor/thor/invocation.rb:116:in `call'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/lib/bundler/vendor/thor/invocation.rb:116:in `invoke'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/lib/bundler/vendor/thor.rb:137:in `start'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/lib/bundler/vendor/thor/base.rb:378:in `start'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/lib/bundler/vendor/thor.rb:124:in `start'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/gems/bundler-0.9.26/bin/bundle:13          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/bin/bundle:19:in `load'          from /home/rodrigo/.rvm/gems/ruby-1.8.7-p174@rails-master/bin/bundle:19

Maybe it would be useful to include a new file README_FOR_GIT_MASTER.

Rodrigo, platforms were added to bundler 1.0.0.beta.10. Try with this version of bundler or master.

Thank you, Santiago.

"gem install bundler --pre" allowed me to "bundle install".

But 'bin/rails --help' still yields:

Thor is not available. If you ran this command from a git checkout of Rails, please make sure thor is installed, and run this command as `ruby /path/to/rails new myapp --dev`

After running bundler, Thor is installed, as shown by "gem list":

*** LOCAL GEMS ***

abstract (1.0.0) builder (2.1.2) bundler (1.0.0.beta.10) columnize (0.3.1) erubis (2.6.6) horo (1.0.0) i18n (0.4.1) json (1.4.3) linecache (0.43) mail (2.2.5) memcache-client (1.8.5) mime-types (1.16) mocha (0.9.8) mysql (2.8.1) nokogiri (1.4.2) pg (0.9.0) polyglot (0.3.1) rack (1.2.1) rack-mount (0.6.9) rack-test (0.5.4) rake (0.8.7) rdoc (2.5.9, 2.5.8) ruby-debug (0.10.3) ruby-debug-base (0.10.3) sqlite3-ruby (1.3.1) system_timer (1.0) text-format (1.0.0) text-hyphen (1.0.0) thor (0.13.8) treetop (1.4.8) tzinfo (0.3.22) yajl-ruby (0.7.7)

Right, so how about changing an existing app to not use ActiveRecord? The app generator doesn’t allow generating over existing files (a decision I don’t understand). And even if it did, we would have to overwrite application.rb which is one of the 2 files that get customizations after generating a new app. Then we would have to bring back our customizations to the newly generated file. Either way you take it, it’s a lot of work.

My suggestion is never using “rails/all.rb” . I liked the older app generator when we got require statements for each of the frameworks:

require “active_record/railtie”

require “action_controller/railtie”

If we want to disable one, we just need to comment it out (same what --skip-activerecord) does.

Rodrigo,

  you should run ruby bin/rails --help --dev or ruby -rubygems bin/rails --help But you're right the error message was not the best it was fixed here http://github.com/rails/rails/commit/514624e53c7b3008e3c492ef01f4d85188cdbbd7

Cheers, Santiago.

Thank you, Santiago. I'll test it when I get home.

Best regards,

Rodrigo.