Mar 19, 2020 Ruby on Rails has been popularizing both concepts along with a variety of other controversial points since the beginning. To learn more about why Rails is so different from many other web-application frameworks and paradigms, examine The Rails Doctrine. Keep up to date with Rails on Twitter and This Week in Rails. Hix on Rails is a Ruby on Rails project generator: a Ruby on Rails Application Template that cuts two days of configuration to a few minutes, everytime. Ruby on Rails - Generators - Ruby provides a script called Generator. This script can be used to generate many useful items in Rails. Most important generators are listed below. Creating and Customizing Rails Generators & TemplatesRails generators are an essential tool if you plan to improve your workflow. With this guide you will learn how to create generators and customize existing ones.After reading this guide, you will know: How to see which generators are available in your application. How to create a generator using templates.
If you're upgrading an existing application, it's a great idea to have good testcoverage before going in. You should also first upgrade to Rails 5.1 in case youhaven't and make sure your application still runs as expected before attemptingan update to Rails 5.2. A list of things to watch out for when upgrading isavailable in theUpgrading Ruby on Railsguide.
Active Storagefacilitates uploading files to a cloud storage service likeAmazon S3, Google Cloud Storage, or Microsoft Azure Storage and attachingthose files to Active Record objects. It comes with a local disk-based servicefor development and testing and supports mirroring files to subordinateservices for backups and migrations.You can read more about Active Storage in theActive Storage Overview guide.
Rails 5.2 ships with built-in Redis cache store.You can read more about this in theCaching with Rails: An Overviewguide.
Rails 5.2 supports HTTP/2 Early Hints.To start the server with Early Hints enabled pass --early-hints
to bin/rails server
.
Added config/credentials.yml.enc
file to store production app secrets.It allows saving any authentication credentials for third-party servicesdirectly in repository encrypted with a key in the config/master.key
file orthe RAILS_MASTER_KEY
environment variable.This will eventually replace Rails.application.secrets
and the encryptedsecrets introduced in Rails 5.1.Furthermore, Rails 5.2opens API underlying Credentials,so you can easily deal with other encrypted configurations, keys, and files.You can read more about this in theSecuring Rails Applicationsguide.
Rails 5.2 ships with a new DSL that allows you to configure aContent Security Policyfor your application. You can configure a global default policy and thenoverride it on a per-resource basis and even use lambdas to inject per-requestvalues into the header such as account subdomains in a multi-tenant application.You can read more about this in theSecuring Rails Applicationsguide.
Please refer to the Changelog for detailed changes.
Deprecate capify!
method in generators and templates.(Pull Request)
Passing the environment's name as a regular argument to therails dbconsole
and rails console
commands is deprecated.The -e
option should be used instead.(Commit)
Deprecate using subclass of Rails::Application
to start the Rails server.(Pull Request)
Deprecate after_bundle
callback in Rails plugin templates.(Pull Request)
Added a shared section to config/database.yml
that will be loaded forall environments.(Pull Request)
Add railtie.rb
to the plugin generator.(Pull Request)
Clear screenshot files in tmp:clear
task.(Pull Request)
Skip unused components when running bin/rails app:update
.If the initial app generation skipped Action Cable, Active Record etc.,the update task honors those skips too.(Pull Request)
Allow passing a custom connection name to the rails dbconsole
command when using a 3-level database configuration.Example: bin/rails dbconsole -c replica
.(Commit)
Properly expand shortcuts for environment's name running the console
and dbconsole
commands.(Commit)
Add bootsnap
to default Gemfile
.(Pull Request)
Support -
as a platform-agnostic way to run a script from stdin withrails runner
(Pull Request)
Add ruby x.x.x
version to Gemfile
and create .ruby-version
root file containing the current Ruby version when new Rails applicationsare created.(Pull Request)
Add --skip-action-cable
option to the plugin generator.(Pull Request)
Add git_source
to Gemfile
for plugin generator.(Pull Request)
Skip unused components when running bin/rails
in Rails plugin.(Commit)
Optimize indentation for generator actions.(Pull Request)
Optimize routes indentation.(Pull Request)
Add --skip-yarn
option to the plugin generator.(Pull Request)
Support multiple versions arguments for gem
method of Generators.(Pull Request)
Derive secret_key_base
from the app name in development and testenvironments.(Pull Request)
Add mini_magick
to default Gemfile
as comment.(Pull Request)
rails new
and rails plugin new
get Active Storage
by default. Add ability to skip Active Storage
with --skip-active-storage
and do so automatically when --skip-active-record
is used.(Pull Request)
Please refer to the Changelog for detailed changes.
Add support for host
, port
, db
and password
options in cable.yml(Pull Request)
Hash long stream identifiers when using PostgreSQL adapter.(Pull Request)
Please refer to the Changelog for detailed changes.
ActionController::ParamsParser::ParseError
.(Commit)#success?
, #missing?
and #error?
aliases ofActionDispatch::TestResponse
.(Pull Request)Add support for recyclable cache keys with fragment caching.(Pull Request)
Change the cache key format for fragments to make it easier to debug keychurn.(Pull Request)
AEAD encrypted cookies and sessions with GCM.(Pull Request)
Protect from forgery by default.(Pull Request)
Enforce signed/encrypted cookie expiry server side.(Pull Request)
Cookies :expires
option supports ActiveSupport::Duration
object.(Pull Request)
Use Capybara registered :puma
server config.(Pull Request)
Simplify cookies middleware with key rotation support.(Pull Request)
Add ability to enable Early Hints for HTTP/2.(Pull Request)
Add headless chrome support to System Tests.(Pull Request)
Add :allow_other_host
option to redirect_back
method.(Pull Request)
Make assert_recognizes
to traverse mounted engines.(Pull Request)
Add DSL for configuring Content-Security-Policy header.(Pull Request,Commit,Commit)
Register most popular audio/video/font mime types supported by modernbrowsers.(Pull Request)
Changed the default system test screenshot output from inline
to simple
.(Commit)
Add headless firefox support to System Tests.(Pull Request)
Add secure X-Download-Options
and X-Permitted-Cross-Domain-Policies
todefault headers set.(Commit)
Changed the system tests to set Puma as default server only when theuser haven't specified manually another server.(Pull Request)
Add Referrer-Policy
header to default headers set.(Commit)
Matches behavior of Hash#each
in ActionController::Parameters#each
.(Pull Request)
Add support for automatic nonce generation for Rails UJS.(Commit)
Update the default HSTS max-age value to 31536000 seconds (1 year)to meet the minimum max-age requirement for https://hstspreload.org/.(Commit)
Add alias method to_hash
to to_h
for cookies
.Add alias method to_h
to to_hash
for session
.(Commit)
Please refer to the Changelog for detailed changes.
image_alt
helper which used to add default alt text tothe images generated by image_tag
.(Pull Request) Add :json
type to auto_discovery_link_tag
to supportJSON Feeds.(Pull Request)
Add srcset
option to image_tag
helper.(Pull Request)
Fix issues with field_error_proc
wrapping optgroup
andselect divider option
.(Pull Request)
Change form_with
to generate ids by default.(Commit)
Add preload_link_tag
helper.(Pull Request)
Allow the use of callable objects as group methods for grouped selects.(Pull Request)
Please refer to the Changelog for detailed changes.
Allow Action Mailer classes to configure their delivery job.(Pull Request)
Add assert_enqueued_email_with
test helper.(Pull Request)
Please refer to the Changelog for detailed changes.
Remove deprecated #migration_keys
.(Pull Request)
Remove deprecated support to quoted_id
when typecastingan Active Record object.(Commit)
Remove deprecated argument default
from index_name_exists?
.(Commit)
Remove deprecated support to passing a class to :class_name
on associations.(Commit)
Remove deprecated methods initialize_schema_migrations_table
andinitialize_internal_metadata_table
.(Commit)
Remove deprecated method supports_migrations?
.(Commit)
Remove deprecated method supports_primary_key?
.(Commit)
Remove deprecated methodActiveRecord::Migrator.schema_migrations_table_name
.(Commit)
Remove deprecated argument name
from #indexes
.(Commit)
Remove deprecated arguments from #verify!
.(Commit)
Remove deprecated configuration .error_on_ignored_order_or_limit
.(Commit)
Remove deprecated method #scope_chain
.(Commit)
Remove deprecated method #sanitize_conditions
.(Commit)
Deprecate supports_statement_cache?
.(Pull Request)
Deprecate passing arguments and block at the same time tocount
and sum
in ActiveRecord::Calculations
.(Pull Request)
Deprecate delegating to arel
in Relation
.(Pull Request)
Deprecate set_state
method in TransactionState
.(Commit)
Deprecate expand_hash_conditions_for_aggregates
without replacement.(Commit)
When calling the dynamic fixture accessor method with no arguments, it nowreturns all fixtures of this type. Previously this method always returnedan empty array.(Pull Request)
Fix inconsistency with changed attributes when overridingActive Record attribute reader.(Pull Request)
Support Descending Indexes for MySQL.(Pull Request)
Fix bin/rails db:forward
first migration.(Commit)
Raise error UnknownMigrationVersionError
on the movement of migrationswhen the current migration does not exist.(Commit)
Respect SchemaDumper.ignore_tables
in rake tasks fordatabases structure dump.(Pull Request)
Add ActiveRecord::Base#cache_version
to support recyclable cache keys viathe new versioned entries in ActiveSupport::Cache
. This also means thatActiveRecord::Base#cache_key
will now return a stable key thatdoes not include a timestamp any more.(Pull Request)
Prevent creation of bind param if casted value is nil.(Pull Request)
Use bulk INSERT to insert fixtures for better performance.(Pull Request)
Merging two relations representing nested joins no longer transformsthe joins of the merged relation into LEFT OUTER JOIN.(Pull Request)
Fix transactions to apply state to child transactions.Previously, if you had a nested transaction and the outer transaction wasrolledback, the record from the inner transaction would still be markedas persisted. It was fixed by applying the state of the parenttransaction to the child transaction when the parent transaction isrolledback. This will correctly mark records from the inner transactionas not persisted.(Commit)
Fix eager loading/preloading association with scope including joins.(Pull Request)
Prevent errors raised by sql.active_record
notification subscribersfrom being converted into ActiveRecord::StatementInvalid
exceptions.(Pull Request)
Skip query caching when working with batches of records(find_each
, find_in_batches
, in_batches
).(Commit)
Change sqlite3 boolean serialization to use 1 and 0.SQLite natively recognizes 1 and 0 as true and false, but does not nativelyrecognize 't' and 'f' as was previously serialized.(Pull Request)
Values constructed using multi-parameter assignment will now use thepost-type-cast value for rendering in single-field form inputs.(Commit)
ApplicationRecord
is no longer generated when generating models. If youneed to generate it, it can be created with rails g application_record
.(Pull Request)
Relation#or
now accepts two relations who have different values forreferences
only, as references
can be implicitly called by where
.(Commit)
When using Relation#or
, extract the common conditions andput them before the OR condition.(Pull Request)
Add binary
fixture helper method.(Pull Request)
Automatically guess the inverse associations for STI.(Pull Request)
Add new error class LockWaitTimeout
which will be raisedwhen lock wait timeout exceeded.(Pull Request)
Update payload names for sql.active_record
instrumentation to bemore descriptive.(Pull Request)
Use given algorithm while removing index from database.(Pull Request)
Passing a Set
to Relation#where
now behaves the same as passingan array.(Commit)
PostgreSQL tsrange
now preserves subsecond precision.(Pull Request)
Raises when calling lock!
in a dirty record.(Commit)
Fixed a bug where column orders for an index weren't written todb/schema.rb
when using the sqlite adapter.(Pull Request)
Fix bin/rails db:migrate
with specified VERSION
.bin/rails db:migrate
with empty VERSION behaves as without VERSION
.Check a format of VERSION
: Allow a migration version numberor name of a migration file. Raise error if format of VERSION
is invalid.Raise error if target migration doesn't exist.(Pull Request)
Add new error class StatementTimeout
which will be raisedwhen statement timeout exceeded.(Pull Request)
update_all
will now pass its values to Type#cast
before passing them toType#serialize
. This means that update_all(foo: 'true')
will properlypersist a boolean.(Commit)
Require raw SQL fragments to be explicitly marked when used inrelation query methods.(Commit,Commit)
Add #up_only
to database migrations for code that is only relevant whenmigrating up, e.g. populating a new column.(Pull Request)
Add new error class QueryCanceled
which will be raisedwhen canceling statement due to user request.(Pull Request)
Don't allow scopes to be defined which conflict with instance methodson Relation
.(Pull Request)
Add support for PostgreSQL operator classes to add_index
.(Pull Request)
Log database query callers.(Pull Request,Pull Request,Pull Request)
Undefine attribute methods on descendants when resetting column information.(Pull Request)
Using subselect for delete_all
with limit
or offset
.(Commit)
Fixed inconsistency with first(n)
when used with limit()
.The first(n)
finder now respects the limit()
, making it consistentwith relation.to_a.first(n)
, and also with the behavior of last(n)
.(Pull Request)
Fix nested has_many :through
associations on unpersisted parent instances.(Commit)
Take into account association conditions when deleting through records.(Commit)
Don't allow destroyed object mutation after save
or save!
is called.(Commit)
Fix relation merger issue with left_outer_joins
.(Pull Request)
Support for PostgreSQL foreign tables.(Pull Request)
Clear the transaction state when an Active Record object is duped.(Pull Request)
Fix not expanded problem when passing an Array object as argumentto the where method using composed_of
column.(Pull Request)
Make reflection.klass
raise if polymorphic?
not to be misused.(Commit)
Fix #columns_for_distinct
of MySQL and PostgreSQL to makeActiveRecord::FinderMethods#limited_ids_for
use correct primary key valueseven if ORDER BY
columns include other table's primary key.(Commit)
Fix dependent: :destroy
issue for has_one/belongs_to relationship wherethe parent class was getting deleted when the child was not.(Commit)
Idle database connections (previously just orphaned connections) are nowperiodically reaped by the connection pool reaper.(Commit)
Please refer to the Changelog for detailed changes.
Fix methods #keys
, #values
in ActiveModel::Errors
.Change #keys
to only return the keys that don't have empty messages.Change #values
to only return the not empty values.(Pull Request)
Add method #merge!
for ActiveModel::Errors
.(Pull Request)
Allow passing a Proc or Symbol to length validator options.(Pull Request)
Execute ConfirmationValidator
validation when _confirmation
's valueis false
.(Pull Request)
Models using the attributes API with a proc default can now be marshalled.(Commit)
Do not lose all multiple :includes
with options in serialization.(Commit)
Please refer to the Changelog for detailed changes.
Remove deprecated :if
and :unless
string filter for callbacks.(Commit)
Remove deprecated halt_callback_chains_on_return_false
option.(Commit)
Deprecate Module#reachable?
method.(Pull Request)
Deprecate secrets.secret_token
.(Commit)
Add fetch_values
for HashWithIndifferentAccess
.(Pull Request)
Add support for :offset
to Time#change
.(Commit)
Add support for :offset
and :zone
to ActiveSupport::TimeWithZone#change
.(Commit)
Pass gem name and deprecation horizon to deprecation notifications.(Pull Request)
Add support for versioned cache entries. This enables the cache stores torecycle cache keys, greatly saving on storage in cases with frequent churn.Works together with the separation of #cache_key
and #cache_version
in Active Record and its use in Action Pack's fragment caching.(Pull Request)
Add ActiveSupport::CurrentAttributes
to provide a thread-isolatedattributes singleton. Primary use case is keeping all the per-requestattributes easily available to the whole system.(Pull Request)
#singularize
and #pluralize
now respect uncountables forthe specified locale.(Commit)
Add default option to class_attribute
.(Pull Request)
Add Date#prev_occurring
and Date#next_occurring
to returnspecified next/previous occurring day of week.(Pull Request)
Add default option to module and class attribute accessors.(Pull Request)
Cache: write_multi
.(Pull Request)
Default ActiveSupport::MessageEncryptor
to use AES 256 GCM encryption.(Pull Request)
Add freeze_time
helper which freezes time to Time.now
in tests.(Pull Request)
Make the order of Hash#reverse_merge!
consistentwith HashWithIndifferentAccess
.(Pull Request)
Add purpose and expiry support to ActiveSupport::MessageVerifier
andActiveSupport::MessageEncryptor
.(Pull Request)
Update String#camelize
to provide feedback when wrong option is passed.(Pull Request)
Module#delegate_missing_to
now raises DelegationError
if target is nil,similar to Module#delegate
.(Pull Request)
Add ActiveSupport::EncryptedFile
andActiveSupport::EncryptedConfiguration
.(Pull Request)
Add config/credentials.yml.enc
to store production app secrets.(Pull Request)
Add key rotation support to MessageEncryptor
and MessageVerifier
.(Pull Request)
Return an instance of HashWithIndifferentAccess
fromHashWithIndifferentAccess#transform_keys
.(Pull Request)
Hash#slice
now falls back to Ruby 2.5+'s built-in definition if defined.(Commit)
IO#to_json
now returns the to_s
representation, rather thanattempting to convert to an array. This fixes a bug where IO#to_json
would raise an IOError
when called on an unreadable object.(Pull Request)
Add same method signature for Time#prev_day
and Time#next_day
in accordance with Date#prev_day
, Date#next_day
.Allows pass argument for Time#prev_day
and Time#next_day
.(Commit)
Add same method signature for Time#prev_month
and Time#next_month
in accordance with Date#prev_month
, Date#next_month
.Allows pass argument for Time#prev_month
and Time#next_month
.(Commit)
Add same method signature for Time#prev_year
and Time#next_year
in accordance with Date#prev_year
, Date#next_year
.Allows pass argument for Time#prev_year
and Time#next_year
.(Commit)
Fix acronym support in humanize
.(Commit)
Allow Range#include?
on TWZ ranges.(Pull Request)
Cache: Enable compression by default for values > 1kB.(Pull Request)
Redis cache store.(Pull Request,Pull Request)
Handle TZInfo::AmbiguousTime
errors.(Pull Request)
MemCacheStore: Support expiring counters.(Commit)
Make ActiveSupport::TimeZone.all
return only time zones that are inActiveSupport::TimeZone::MAPPING
.(Pull Request)
Changed default behaviour of ActiveSupport::SecurityUtils.secure_compare
,to make it not leak length information even for variable length string.Renamed old ActiveSupport::SecurityUtils.secure_compare
tofixed_length_secure_compare
, and started raising ArgumentError
incase of length mismatch of passed strings.(Pull Request)
Use SHA-1 to generate non-sensitive digests, such as the ETag header.(Pull Request,Pull Request)
assert_changes
will always assert that the expression changes,regardless of from:
and to:
argument combinations.(Pull Request)
Add missing instrumentation for read_multi
in ActiveSupport::Cache::Store
.(Pull Request)
Support hash as first argument in assert_difference
.This allows to specify multiple numeric differences in the same assertion.(Pull Request)
Caching: MemCache and Redis read_multi
and fetch_multi
speedup.Read from the local in-memory cache before consulting the backend.(Commit)
Please refer to the Changelog for detailed changes.
ActiveJob::Base.discard_on
to allow customhandling of discard jobs.(Pull Request)Please refer to the Changelog for detailed changes.
AddThreading and Code Execution in RailsGuide.(Pull Request)
Add Active Storage Overview Guide.(Pull Request)
See thefull list of contributors to Railsfor the many people who spent many hours making Rails, the stable and robustframework it is. Kudos to all of them.
You're encouraged to help improve the quality of this guide.
Please contribute if you see any typos or factual errors. To get started, you can read our documentation contributions section.
You may also find incomplete content or stuff that is not up to date. Please do add any missing documentation for master. Make sure to check Edge Guides first to verify if the issues are already fixed or not on the master branch. Check the Ruby on Rails Guides Guidelines for style and conventions.
If for whatever reason you spot something to fix but cannot patch it yourself, please open an issue.
And last but not least, any kind of discussion regarding Ruby on Rails documentation is very welcome on the rubyonrails-docs mailing list.
DEFAULT_ALIASES | = | {rails: {actions: '-a',orm: '-o',javascripts: '-j',javascript_engine: '-je',resource_controller: '-c',scaffold_controller: '-c',stylesheets: '-y',stylesheet_engine: '-se',scaffold_stylesheet: '-ss',template_engine: '-e',test_framework: '-t'},test_unit: {fixture_replacement: '-r',}} |
DEFAULT_OPTIONS | = | {rails: {api: false,assets: true,force_plural: false,helper: true,integration_tool: nil,orm: false,resource_controller: :controller,resource_route: true,scaffold_controller: :scaffold_controller,stylesheets: true,stylesheet_engine: :css,scaffold_stylesheet: true,system_tests: nil,test_framework: nil,template_engine: :erb}} |
RAILS_DEV_PATH | = | File.expand_path('./././././.', __dir__) |
We need to store the |
Configure generators for API
only applications. It basically hides everything that is usually browser related, such as assets and session migration generators, and completely disable helpers and assets so generators such as scaffold won't create them.
Source: show on GitHub
Hold configured generators fallbacks. If a plugin developer wants a generator group to fallback to another group in case of missing generators, they can add a fallback.
For example, shoulda is considered a test_framework and is an extension of test_unit. However, most part of shoulda generators are similar to test_unit ones.
Shoulda then can tell generators to search for test_unit generators when some of them are not available by adding a fallback:
Source: show on GitHub
Show help message with available generators.
Source: show on GitHub
Returns an array of generator namespaces that are hidden. Generator namespaces may be hidden for a variety of reasons. Some are aliased such as “rails:migration” and can be invoked with the shorter “migration”, others are private to other generators such as “css:scaffold”.
Source: show on GitHub
Source: show on GitHub
Receives a namespace, arguments and the behavior to invoke the generator. It's used as the default entry point for generate, destroy and update commands.
Source: show on GitHub
Remove the color from output.
Source: show on GitHub
Source: show on GitHub
Source: show on GitHub
Source: show on GitHub
About This GameThe desperate leadership of a doomed Soviet Union travels back in time to change history and restore the glory of Mother Russia. Command and conquer red alert 3 generated key download.
Source: show on GitHub
Source: show on GitHub
Source: show on GitHub
Source: show on GitHub