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:
Comment
/ Remove any database gems ( mysql, mysql2, sqlite, pg, mongoid,
etc..) from your Gemfile and then run bundle.
- 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'
- 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
Post a Comment