Rails 4 WITH NO Database



Sometimes, you may want to create a Rails application without ActiveRecord or a database. There might be situations like, Your application only store data using third party APIs, or storing in to files or might not have any persistent data at all. Since Rails stands for the common case (database backed application), by default it fails to start the server without a database connection.

You can simply build a Rails app without a database:
  1. Comment / Remove any database gems ( mysql, mysql2, sqlite, pg, mongoid, etc..) from your Gemfile and then run bundle. 
     
  2. Open your application.rb. By default, in Rails 4.0 you can see one line which requires all of Rails:
    require 'rails/all'
    This includes ActiveRecord also, and requires a database connection. Instead, you can include the specific parts of Rails that you gonna use.
    See below:
    require 'action_controller/railtie'
    require 'action_mailer/railtie'
    require 'active_model/railtie'
    require 'sprockets/railtie'
    require 'rails/test_unit/railtie'
     
  3. The default app generated by Rails 4.0 has one reference to active record which must be removed, in config/environments/development.rb:
    config.active_record.migration_error = :page_load 
    4. Remove any references to active_record in your configuration 
Now run your application with out any backend :)

Comments

Popular posts from this blog

Rails Kaminari - Ajax pagination

Rails 4, MySQL, and Emoji (Mysql2::Error: Incorrect string value: '\xF0\x9F\x8C\x9D')