Ruby on Rails 4.2 has been released! Below you will find a copy of each of the files generated during new application creation. This will assist you when upgrading to Rails 4.2.

Notable changes to Rails 4.2 include:

  • Ruby Web Console - An interactive Ruby Web Console on development. No more running rails c!
  • Active Job - A Job Framework for running Ruby Jobs that works with many different backends such as Resque, Delayed Job, Sidekiq, etc.
  • ActiveMailer #deliver_later - Delivers your emails asynchonously.
  • Adequate Record - A Project to speed up ActiveRecord. According to the release notes, common queries are more than twice as fast as in Rails 4.1
  • Foreign Key Support - add_foreign_key and remove_foreign_key have been added to allow you to easily create foreign keys from within the framework.
  • Rails.application.config_for - A handy little tool that will automatically load YAML files from the config folder.

I hope to go over some of the new Rails 4.2 features in futures articles. For now, enjoy!



The contents of the Rails 4.2 Gemfile are listed below. Notable changes include the web-console gem as well as the byebug debugger gem.


            source 'https://rubygems.org'


            # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
            gem 'rails', '4.2.0'
            # Use sqlite3 as the database for Active Record
            gem 'sqlite3'
            # Use SCSS for stylesheets
            gem 'sass-rails', '~> 5.0'
            # Use Uglifier as compressor for JavaScript assets
            gem 'uglifier', '>= 1.3.0'
            # Use CoffeeScript for .coffee assets and views
            gem 'coffee-rails', '~> 4.1.0'
            # See https://github.com/sstephenson/execjs#readme for more supported runtimes
            # gem 'therubyracer', platforms: :ruby

            # Use jquery as the JavaScript library
            gem 'jquery-rails'
            # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
            gem 'turbolinks'
            # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
            gem 'jbuilder', '~> 2.0'
            # bundle exec rake doc:rails generates the API under doc/api.
            gem 'sdoc', '~> 0.4.0', group: :doc

            # Use ActiveModel has_secure_password
            # gem 'bcrypt', '~> 3.1.7'

            # Use Unicorn as the app server
            # gem 'unicorn'

            # Use Capistrano for deployment
            # gem 'capistrano-rails', group: :development

            group :development, :test do
              # Call 'byebug' anywhere in the code to stop execution and get a debugger console
              gem 'byebug'

              # Access an IRB console on exception pages or by using <%= console %> in views
              gem 'web-console', '~> 2.0'

              # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
              gem 'spring'
            end
            


As with Rails 4.1, Rails 4.2 features only minor changes to the config/application.rb file.


          require File.expand_path('../boot', __FILE__)

          require 'rails/all'

          # Require the gems listed in Gemfile, including any gems
          # you've limited to :test, :development, or :production.
          Bundler.require(*Rails.groups)

          module Rails42ExampleApp
            class Application < Rails::Application
              # Settings in config/environments/* take precedence over those specified here.
              # Application configuration should go into files in config/initializers
              # -- all .rb files in that directory are automatically loaded.

              # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
              # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
              # config.time_zone = 'Central Time (US & Canada)'

              # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
              # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
              # config.i18n.default_locale = :de

              # Do not swallow errors in after_commit/after_rollback callbacks.
              config.active_record.raise_in_transactional_callbacks = true
            end
          end

          


Once again, only a few minor changes for the config/environments/development.rb file as well.


          Rails.application.configure do
            # Settings specified here will take precedence over those in config/application.rb.

            # In the development environment your application's code is reloaded on
            # every request. This slows down response time but is perfect for development
            # since you don't have to restart the web server when you make code changes.
            config.cache_classes = false

            # Do not eager load code on boot.
            config.eager_load = false

            # Show full error reports and disable caching.
            config.consider_all_requests_local       = true
            config.action_controller.perform_caching = false

            # Don't care if the mailer can't send.
            config.action_mailer.raise_delivery_errors = false

            # Print deprecation notices to the Rails logger.
            config.active_support.deprecation = :log

            # Raise an error on page load if there are pending migrations.
            config.active_record.migration_error = :page_load

            # Debug mode disables concatenation and preprocessing of assets.
            # This option may cause significant delays in view rendering with a large
            # number of complex assets.
            config.assets.debug = true

            # Asset digests allow you to set far-future HTTP expiration dates on all assets,
            # yet still be able to expire them through the digest params.
            config.assets.digest = true

            # Adds additional error checking when serving assets at runtime.
            # Checks for improperly declared sprockets dependencies.
            # Raises helpful error messages.
            config.assets.raise_runtime_errors = true

            # Raises error for missing translations
            # config.action_view.raise_on_missing_translations = true
          end

          

One important notable change here. config.serve_static_assets has been changed to config.serve_static_files. Remember this!


          Rails.application.configure do
            # Settings specified here will take precedence over those in config/application.rb.

            # Code is not reloaded between requests.
            config.cache_classes = true

            # Eager load code on boot. This eager loads most of Rails and
            # your application in memory, allowing both threaded web servers
            # and those relying on copy on write to perform better.
            # Rake tasks automatically ignore this option for performance.
            config.eager_load = true

            # Full error reports are disabled and caching is turned on.
            config.consider_all_requests_local       = false
            config.action_controller.perform_caching = true

            # Enable Rack::Cache to put a simple HTTP cache in front of your application
            # Add `rack-cache` to your Gemfile before enabling this.
            # For large-scale production use, consider using a caching reverse proxy like
            # NGINX, varnish or squid.
            # config.action_dispatch.rack_cache = true

            # Disable serving static files from the `/public` folder by default since
            # Apache or NGINX already handles this.
            config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

            # Compress JavaScripts and CSS.
            config.assets.js_compressor = :uglifier
            # config.assets.css_compressor = :sass

            # Do not fallback to assets pipeline if a precompiled asset is missed.
            config.assets.compile = false

            # Asset digests allow you to set far-future HTTP expiration dates on all assets,
            # yet still be able to expire them through the digest params.
            config.assets.digest = true

            # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

            # Specifies the header that your server uses for sending files.
            # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
            # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

            # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
            # config.force_ssl = true

            # Use the lowest log level to ensure availability of diagnostic information
            # when problems arise.
            config.log_level = :debug

            # Prepend all log lines with the following tags.
            # config.log_tags = [ :subdomain, :uuid ]

            # Use a different logger for distributed setups.
            # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

            # Use a different cache store in production.
            # config.cache_store = :mem_cache_store

            # Enable serving of images, stylesheets, and JavaScripts from an asset server.
            # config.action_controller.asset_host = 'http://assets.example.com'

            # Ignore bad email addresses and do not raise email delivery errors.
            # Set this to true and configure the email server for immediate delivery to raise delivery errors.
            # config.action_mailer.raise_delivery_errors = false

            # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
            # the I18n.default_locale when a translation cannot be found).
            config.i18n.fallbacks = true

            # Send deprecation notices to registered listeners.
            config.active_support.deprecation = :notify

            # Use default logging formatter so that PID and timestamp are not suppressed.
            config.log_formatter = ::Logger::Formatter.new

            # Do not dump schema after migrations.
            config.active_record.dump_schema_after_migration = false
          end

          

A few minor changes here. Also again note that config.serve_static_assets has been changed to config.serve_static_files.


            Rails.application.configure do
              # Settings specified here will take precedence over those in config/application.rb.

              # The test environment is used exclusively to run your application's
              # test suite. You never need to work with it otherwise. Remember that
              # your test database is "scratch space" for the test suite and is wiped
              # and recreated between test runs. Don't rely on the data there!
              config.cache_classes = true

              # Do not eager load code on boot. This avoids loading your whole application
              # just for the purpose of running a single test. If you are using a tool that
              # preloads Rails for running tests, you may have to set it to true.
              config.eager_load = false

              # Configure static file server for tests with Cache-Control for performance.
              config.serve_static_files   = true
              config.static_cache_control = 'public, max-age=3600'

              # Show full error reports and disable caching.
              config.consider_all_requests_local       = true
              config.action_controller.perform_caching = false

              # Raise exceptions instead of rendering exception templates.
              config.action_dispatch.show_exceptions = false

              # Disable request forgery protection in test environment.
              config.action_controller.allow_forgery_protection = false

              # Tell Action Mailer not to deliver emails to the real world.
              # The :test delivery method accumulates sent emails in the
              # ActionMailer::Base.deliveries array.
              config.action_mailer.delivery_method = :test

              # Randomize the order test cases are executed.
              config.active_support.test_order = :random

              # Print deprecation notices to the stderr.
              config.active_support.deprecation = :stderr

              # Raises error for missing translations
              # config.action_view.raise_on_missing_translations = true
            end

          

For the people that still haven't upgraded.


          # Be sure to restart your server when you modify this file.

          # Your secret key is used for verifying the integrity of signed cookies.
          # If you change this key, all old signed cookies will become invalid!

          # Make sure the secret is at least 30 characters and all random,
          # no regular words or you'll be exposed to dictionary attacks.
          # You can use `rake secret` to generate a secure secret key.

          # Make sure the secrets in this file are kept private
          # if you're sharing your code publicly.

          development:
            secret_key_base: <A SECRET KEY>

          test:
            secret_key_base: <A SECRET KEY>

          # Do not keep production secrets in the repository,
          # instead read values from the environment.
          production:
            secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>