Writing a Ruby on Rails application without using a database

Some of you may be wondering "why would you want to use Rails without a database?" There are several situations why a database would not be needed, and I've run into quite a few of them. One of the specific cases was when I wanted to write a web interface for an application that only had a REST interface available to the public.

If you find yourself needing to write a Rails application without a database, just do the following:

For Rails 1.0 and up:
config/environment.rb:

config.frameworks -= [ :active_record ]

test/test_helper.rb

class Test::Unit::TestCase
  self.use_transactional_fixtures = false
  self.use_instantiated_fixtures  = false
  def load_fixtures
  end
end

For Rails 2.1 and up: Comment out both of the lines that begin with ActiveRecord::Base in config/initializers/new_rails_defaults.rb:

if defined?(ActiveRecord)
  # Include Active Record class name as root for JSON serialized output.
  # ActiveRecord::Base.include_root_in_json = true
 
  # Store the full class name (including module namespace) in STI type column.
  # ActiveRecord::Base.store_full_sti_class = true
end

For more details, review the full article on rubyonrails.org.

Printed from: http://rackerhacker.com/2009/01/09/writing-a-ruby-on-rails-application-without-using-a-database/ .
© Major Hayden 2012.

1 Comment   »

  • Arivarasan says:

    Nice work!

    It works for me,
    first i removed the comment for config.frameworks -= [ :active_record ] in 'config/environment.rb'
    then i added comments inside the file 'config/initializers/new_rails_defaults.rb.'

    Now it works for me.

    But i cannot understand what to do in test/test_helper.rb.

    my test_helper.rb is like this

    ENV["RAILS_ENV"] = "test"
    require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
    require 'test_help'
    class ActiveSupport::TestCase
    self.use_transactional_fixtures = true
    self.use_instantiated_fixtures = false
    fixtures :all
    end

    Please tell me the purpose of the test_helper.rb file and what to do now

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this