Configuration files for rails can be found in config/environments/
. By default rails has 3 environments, development
, production
and test
. By editing each file you are editing the configuration for that environment only.
Rails also has a configuration file in config/application.rb
. This is a common configuration file as any settings defined here are overwritten by the config specified in each environment.
You add or modify configuration options within the Rails.application.configure do
block and configuration options start with config.
Database configuration of a rails project lies in a file config/database.yml
. If you create a project using rails new
command and don't specify a database engine to be used then rails uses sqlite
as the default database. A typical database.yml
file with default configuration will look similar to following.
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
If you want to change the default database while creating a new project you can specify database: rails new hello_world --database=mysql
The following configuration options should be called on a Rails::Railtie
object
config.action_controller.asset_host
app
false
and in the production and test modes it defaults to true
config.cache_classes
setting:monday
):file_store
, :memory_store
, mem_cache_store
or null_store
.UTF-8
:debug
in all environments.The following configuration options can be used for configuring assets
development mode
:closure
, :uglifier
and :yui
rake assets:precompile
is runMD-5
fingerprints in the asset names. It defaults to true in development modeSprockets
compilation in production modeRails allows you to configure what generators are used when running rails generate
commands. This method, config.generators
takes a block
config.generators do |g|
g.orm :active_record
g.test_framework :test_unit
end
Here are some of the options
Option | Description | Default |
---|---|---|
assets | Creates assets when generating scaffold | true |
force_plural | Allows pluralized model names | false |
helper | Determines whether to generate helpers | true |
integration_tool | Specify integration tool | test_unit |
javascript_engine | Configures JS engine | :js |
resource_route | Generates resource route | true |
stylesheet_engine | Configures stylesheet engine | :cs |
scaffold_stylesheet | Creates CSS upon scaffolding | true |
test_framework | Specify Test Framework | Minitest |
template_engine | Configures template engine | :erb |