2020-09-17 15:33:27 -04:00
* Return a 405 Method Not Allowed response when a request uses an unknown HTTP method.
Fixes #38998 .
*Loren Norman*
2020-10-21 01:21:07 -04:00
* Make railsrc file location xdg-specification compliant
`rails new` will now look for the default `railsrc` file at
`$XDG_CONFIG_HOME/rails/railsrc` (or `~/.config/rails/railsrc` if
`XDG_CONFIG_HOME` is not set). If this file does not exist, `rails new`
will fall back to `~/.railsrc` .
The fallback behaviour means this does not cause any breaking changes.
*Nick Wolf*
2020-06-23 18:07:53 -04:00
* Change the default logging level from :debug to :info to avoid inadvertent exposure of personally
identifiable information (PII) in production environments.
*Eric M. Payne*
2020-07-17 10:54:04 -04:00
* Automatically generate abstract class when using multiple databases.
When generating a scaffold for a multiple database application, Rails will now automatically generate the abstract class for the database when the database argument is passed. This abstract class will include the connection information for the writing configuration and any models generated for that database will automatically inherit from the abstract class.
Usage:
2020-08-20 19:50:25 -04:00
```bash
$ bin/rails generate scaffold Pet name:string --database=animals
2020-07-17 10:54:04 -04:00
```
Will create an abstract class for the animals connection.
```ruby
class AnimalsRecord < ApplicationRecord
self.abstract_class = true
connects_to database: { writing: :animals }
end
```
And generate a `Pet` model that inherits from the new `AnimalsRecord` :
```ruby
class Pet < AnimalsRecord
end
```
If you already have an abstract class and it follows a different pattern than Rails defaults, you can pass a parent class with the database argument.
2020-08-20 19:50:25 -04:00
```bash
$ bin/rails generate scaffold Pet name:string --database=animals --parent=SecondaryBase
2020-07-17 10:54:04 -04:00
```
2020-07-30 03:26:54 -04:00
This will ensure the model inherits from the `SecondaryBase` parent instead of `AnimalsRecord`
2020-07-17 10:54:04 -04:00
```ruby
class Pet < SecondaryBase
end
```
*Eileen M. Uchitelle* , *John Crepezzi*
2020-07-14 14:02:43 -04:00
* Accept params from url to prepopulate the Inbound Emails form in Rails conductor.
*Chris Oliver*
2020-06-02 16:29:02 -04:00
* Create a new rails app using a minimal stack.
`rails new cool_app --minimal`
All the following are excluded from your minimal stack:
- action_cable
- action_mailbox
- action_mailer
- action_text
- active_job
- active_storage
- bootsnap
- jbuilder
- spring
- system_tests
- turbolinks
- webpack
*Haroon Ahmed* , *DHH*
2020-05-17 18:12:11 -04:00
* Add default ENV variable option with BACKTRACE to turn off backtrace cleaning when debugging framework code in the
2020-05-17 11:52:05 -04:00
generated config/initializers/backtrace_silencers.rb.
2020-05-17 18:12:11 -04:00
2020-05-17 11:52:05 -04:00
`BACKTRACE=1 ./bin/rails runner "MyClass.perform"`
2020-05-17 18:12:11 -04:00
*DHH*
2020-05-17 04:10:47 -04:00
* The autoloading guide for Zeitwerk mode documents how to autoload classes
during application boot in a safe way.
*Haroon Ahmed* , *Xavier Noria*
2020-05-12 02:12:05 -04:00
* The `classic` autoloader starts its deprecation cycle.
New Rails projects are strongly discouraged from using `classic` , and we recommend that existing projects running on `classic` switch to `zeitwerk` mode when upgrading. Please check the [_Upgrading Ruby on Rails_ ](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html ) guide for tips.
2020-05-12 02:16:41 -04:00
*Xavier Noria*
2020-05-10 20:22:49 -04:00
* Adds `rails test:all` for running all tests in the test directory.
This runs all test files in the test directory, including system tests.
*Niklas Häusele*
2019-06-19 04:22:46 -04:00
* Add `config.generators.after_generate` for processing to generated files.
Register a callback that will get called right after generators has finished.
*Yuji Yaginuma*
2020-05-03 09:08:49 -04:00
* Make test file patterns configurable via Environment variables
This makes test file patterns configurable via two environment variables:
`DEFAULT_TEST` , to configure files to test, and `DEFAULT_TEST_EXCLUDE` ,
to configure files to exclude from testing.
These values were hardcoded before, which made it difficult to add
new categories of tests that should not be executed by default (e.g:
smoke tests).
*Jorge Manrubia*
2020-02-25 15:19:13 -05:00
* No longer include `rake rdoc` task when generating plugins.
To generate docs, use the `rdoc lib` command instead.
*Jonathan Hefner*
2020-03-24 20:54:12 -04:00
* Allow relative paths with trailing slashes to be passed to `rails test` .
*Eugene Kenny*
2020-03-11 11:47:50 -04:00
* Add `rack-mini-profiler` gem to the default `Gemfile` .
`rack-mini-profiler` displays performance information such as SQL time and flame graphs.
It's enabled by default in development environment, but can be enabled in production as well.
See the gem [README ](https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md ) for information on how to enable it in production.
*Osama Sayegh*
2020-02-25 00:14:54 -05:00
* `rails stats` will now count TypeScript files toward JavaScript stats.
2020-02-18 17:41:16 -05:00
*Joshua Cody*
2020-02-09 17:04:29 -05:00
* Run `git init` when generating plugins.
Opt out with `--skip-git` .
*OKURA Masafumi*
2020-02-25 00:14:54 -05:00
* Add benchmark generator.
2019-12-12 14:52:21 -05:00
Introduce benchmark generator to benchmark Rails applications.
`rails generate benchmark opt_compare`
This creates a benchmark file that uses [`benchmark-ips` ](https://github.com/evanphx/benchmark-ips ).
By default, two code blocks can be benchmarked using the `before` and `after` reports.
You can run the generated benchmark file using:
`ruby script/benchmarks/opt_compare.rb`
*Kevin Jalbert* , *Gannon McGibbon*
2020-02-25 00:14:54 -05:00
* Cache compiled view templates when running tests by default.
2020-01-21 03:10:21 -05:00
2019-12-12 14:52:21 -05:00
When generating a new app without `--skip-spring` , caching classes is
disabled in `environments/test.rb` . This implicitly disables caching
view templates too. This change will enable view template caching by
adding this to the generated `environments/test.rb` :
2020-01-21 03:10:21 -05:00
2020-01-21 09:16:39 -05:00
```ruby
2020-01-21 03:10:21 -05:00
config.action_view.cache_template_loading = true
2020-01-21 09:16:39 -05:00
```
2019-12-12 14:52:21 -05:00
2020-01-21 03:10:21 -05:00
*Jorge Manrubia*
2020-02-25 00:14:54 -05:00
* Introduce middleware move operations.
Delayed middleware delete does not allow move operations
While trying to fix #16433, we made the middleware deletions always
happen at the end. While this works for the case of deleting the
Rack::Runtime middleware, it makes operations like the following
misbehave.
```ruby
gem "bundler", "< 1.16"
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
end
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
middleware.insert_after ActionDispatch::Session::CookieStore, ::Rails::Rack::Logger, config.log_tags
middleware.delete ::Rails::Rack::Logger
end
require "minitest/autorun"
require "rack/test"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
get "/"
assert last_response.ok?
end
private
def app
Rails.application
end
end
```
In the case ☝️ the ::Rails::Rack::Logger would be deleted instead of
moved, because the order of middleware stack building execution will be:
```ruby
[:insert, ActionDispatch::Session::CookieStore, [::Rails::Rack::Logger]]
[:delete, ::Rails::Rack::Logger, [config.log_tags]]
```
This is pretty surprising and hard to reason about behaviour, unless you
go spelunking into the Rails configuration code.
I have a few solutions in mind and all of them have their drawbacks.
1. Introduce a `Rails::Configuration::MiddlewareStackProxy#delete!` that
delays the deleted operations. This will make `#delete` to be executed
in order. The drawback here is backwards incompatible behavior and a new
public method.
2. Just revert to the old operations. This won't allow people to delete
the `Rack::Runtime` middleware.
3. Legitimize the middleware moving with the new `#move_after` and
`#move_before` methods. This does not breaks any backwards
compatibility, but includes 2 new methods to the middleware stack.
I have implemented `3.` in this pull request.
Happy holidays! 🎄
2020-01-07 13:20:03 -05:00
With this change, you no longer need to delete and reinsert a middleware to
move it from one place to another in the stack:
```ruby
config.middleware.move_before ActionDispatch::Flash, Magical::Unicorns
```
This will move the `Magical::Unicorns` middleware before
`ActionDispatch::Flash` . You can also move it after with:
```ruby
config.middleware.move_after ActionDispatch::Flash, Magical::Unicorns
```
*Genadi Samokovarov*
2020-02-25 00:14:54 -05:00
* Generators that inherit from NamedBase respect `--force` option.
2019-10-08 20:05:35 -04:00
2020-01-07 11:12:05 -05:00
*Josh Brody*
2019-10-08 20:05:35 -04:00
2017-02-27 16:55:30 -05:00
* Allow configuration of eager_load behaviour for rake environment:
2019-12-17 20:10:14 -05:00
2020-01-07 11:12:05 -05:00
config.rake_eager_load
2017-02-27 16:55:30 -05:00
Defaults to `false` as per previous behaviour.
*Thierry Joyal*
2020-02-25 00:14:54 -05:00
* Ensure Rails migration generator respects system-wide primary key config.
2019-10-28 22:17:09 -04:00
When rails is configured to use a specific primary key type:
2020-01-07 11:12:05 -05:00
```ruby
2019-10-28 22:17:09 -04:00
config.generators do |g|
g.orm :active_record, primary_key_type: :uuid
end
```
Previously:
2020-08-20 19:50:25 -04:00
```bash
2019-10-28 22:17:09 -04:00
$ bin/rails g migration add_location_to_users location:references
2020-01-07 11:12:05 -05:00
```
2019-10-28 22:17:09 -04:00
The references line in the migration would not have `type: :uuid` .
This change causes the type to be applied appropriately.
2020-02-25 00:14:54 -05:00
*Louis-Michel Couture* , *Dermot Haughey*
2019-10-28 22:17:09 -04:00
2020-02-25 00:14:54 -05:00
* Deprecate `Rails::DBConsole#config` .
2019-12-13 16:54:13 -05:00
2020-01-07 11:12:05 -05:00
`Rails::DBConsole#config` is deprecated without replacement. Use `Rails::DBConsole.db_config.configuration_hash` instead.
2019-12-13 16:54:13 -05:00
*Eileen M. Uchitelle* , *John Crepezzi*
2020-01-07 11:12:05 -05:00
* `Rails.application.config_for` merges shared configuration deeply.
2019-12-09 01:17:29 -05:00
```yaml
# config/example.yml
shared:
foo:
bar:
baz: 1
development:
foo:
bar:
qux: 2
```
```ruby
# Previously
Rails.application.config_for(:example)[:foo][:bar] #=> { qux: 2 }
# Now
Rails.application.config_for(:example)[:foo][:bar] #=> { baz: 1, qux: 2 }
```
*Yuhei Kiriyama*
2019-12-03 15:43:10 -05:00
* Remove access to values in nested hashes returned by `Rails.application.config_for` via String keys.
```yaml
# config/example.yml
development:
options:
key: value
```
```ruby
Rails.application.config_for(:example).options
```
This used to return a Hash on which you could access values with String keys. This was deprecated in 6.0, and now doesn't work anymore.
*Étienne Barrié*
2019-12-02 05:56:11 -05:00
* Configuration files for environments (`config/environments/*.rb`) are
now able to modify `autoload_paths` , `autoload_once_paths` , and
`eager_load_paths` .
2020-01-14 22:11:40 -05:00
As a consequence, applications cannot autoload within those files. Before, they technically could, but changes in autoloaded classes or modules had no effect anyway in the configuration because reloading does not reboot.
2019-12-02 05:56:11 -05:00
Ways to use application code in these files:
* Define early in the boot process a class that is not reloadable, from which the application takes configuration values that get passed to the framework.
```ruby
# In config/application.rb, for example.
require "#{Rails.root}/lib/my_app/config"
# In config/environments/development.rb, for example.
config.foo = MyApp::Config.foo
```
* If the class has to be reloadable, then wrap the configuration code in a `to_prepare` block:
```ruby
config.to_prepare do
config.foo = MyModel.foo
end
```
That assigns the latest `MyModel.foo` to `config.foo` when the application boots, and each time there is a reload. But whether that has an effect or not depends on the configuration point, since it is not uncommon for engines to read the application configuration during initialization and set their own state from them. That process happens only on boot, not on reloads, and if that is how `config.foo` worked, resetting it would have no effect in the state of the engine.
*Allen Hsu* & *Xavier Noria*
2019-11-23 19:20:00 -05:00
* Support using environment variable to set pidfile.
*Ben Thorner*
2019-04-22 21:03:11 -04:00
2019-04-24 15:57:14 -04:00
Please check [6-0-stable ](https://github.com/rails/rails/blob/6-0-stable/railties/CHANGELOG.md ) for previous changes.