Commit Graph

7050 Commits

Author SHA1 Message Date
Wojciech Wnętrzak 6d0773a468
Adjust application pack in webpacker guide
This is how it looks like when generated in the new app (via Rails 6.1.3)

[ci skip]
2021-02-20 16:54:34 +01:00
Santiago Bartesaghi ee3cdbecaf
Remove mention to use ActionMailer to receive emails [ci skip] 2021-02-19 14:36:30 -05:00
Ryuta Kamizono 0618d2d84a Allow new syntax for `enum` to avoid leading `_` from reserved options
Unlike other features built on Attribute API, reserved options for
`enum` has leading `_`.

* `_prefix`/`_suffix`: #19813, #20999
* `_scopes`: #34605
* `_default`: #39820

That is due to `enum` takes one hash argument only, which contains both
enum definitions and reserved options.

I propose new syntax for `enum` to avoid leading `_` from reserved
options, by allowing `enum(attr_name, ..., **options)` more Attribute
API like syntax.

Before:

```ruby
class Book < ActiveRecord::Base
  enum status: [ :proposed, :written ], _prefix: true, _scopes: false
  enum cover: [ :hard, :soft ], _suffix: true, _default: :hard
end
```

After:

```ruby
class Book < ActiveRecord::Base
  enum :status, [ :proposed, :written ], prefix: true, scopes: false
  enum :cover, [ :hard, :soft ], suffix: true, default: :hard
end
```
2021-02-19 14:43:40 +09:00
Ryan Bigg c9955d3d03 Add redirect_back directive to Rails 5.0 -> 5.1 upgrade guide 2021-02-19 08:39:18 +11:00
Rafael França 907cb05dce
Merge pull request #41438 from soartec-lab/task/add-document-for-ar-eager-load-method
Added guides for Active Record `preload` and `eager_load`. [skip ci]
2021-02-15 18:24:24 -05:00
Jonathan Hefner be7185bbae
Merge pull request #41436 from santib/fix-active-storage-sharpening-docs
Fix Upgrading guides [ci skip]
2021-02-15 12:01:52 -06:00
Santiago Bartesaghi 7f7ed5ed9b Fix Upgrading guides [ci skip] 2021-02-15 14:51:36 -03:00
Santiago Bartesaghi 25e027ed19 Fix docs formatting [ci skip] 2021-02-15 11:44:15 -03:00
Vipul A M eb7cee0169
Merge pull request #40998 from justin-robinson/master
[ci skip] instruct to change active_storage_variant_records.id column type to U…
2021-02-15 14:53:19 +05:30
Justin Robinson b0c8e9e1ab
instruct to change active_storage_variant_records.id column type to UUID if using UUID for active storage
Update guides/source/active_storage_overview.md

Co-authored-by: Vipul A M <vipul@hey.com>
2021-02-14 01:39:47 -08:00
soartec-lab ba3933c4db Added guides for Active Record `preload` and `eager_load`.[skip ci] 2021-02-14 12:19:27 +09:00
Sebastien Auriault 24d1615789 Add missing ActionView helper number_to_human in guides 2021-02-11 22:02:30 -05:00
Calle Luks 6dbd73d826
Improve AJAX example [ci skip]
The example uses `fetch` to retrieve HTML from the server and append it to an element on the page. This commit updates the example to append the response HTML rather than the full response object.
2021-02-11 16:07:18 +01:00
Alex Ghiculescu 1d1c9f9fe7 Avoid footguns in `rails app:update`
While upgrading a Rails 6 app to Rails 6.1, I noticed that `rails app:update` asks you to review some file changes that you'd basically never want to accept. In this PR, I propose we make the update task do a bit less, by not offering to overwrite files where the developer has almost certainly changed them from the default. Specific changes:

Don't replace the following files, as they change very rarely at the framework level, so if the user has changes they almost certainly intend to keep them:
- [config/boot.rb](https://github.com/rails/rails/commits/master/railties/lib/rails/generators/rails/app/templates/config/boot.rb.tt)
- [config/environment.rb](https://github.com/rails/rails/commits/master/railties/lib/rails/generators/rails/app/templates/config/environment.rb.tt)
- [config/storage.yml](https://github.com/rails/rails/commits/master/railties/lib/rails/generators/rails/app/templates/config/storage.yml.tt)
- [config/spring.rb](https://github.com/rails/rails/commits/master/railties/lib/rails/generators/rails/app/templates/config/spring.rb.tt)
- [config/cable.yml](https://github.com/rails/rails/commits/master/railties/lib/rails/generators/rails/app/templates/config/cable.yml.tt)
- [config/puma.rb](https://github.com/rails/rails/commits/master/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt)
- [config.ru](https://github.com/rails/rails/commits/master/railties/lib/rails/generators/rails/app/templates/config.ru.tt)

Don't overwrite the config/locales directory. There's basically no chance you'll want to replace your current `config/locales/en.yml` with a [hello world](https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/app/templates/config/locales/en.yml).

Don't replace config/routes.rb. It's so unlikely that the user will want to replace their routes file with [an empty file](https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/app/templates/config/routes.rb.tt).

With these changes, you will still be prompted to accept/decline changes to these files when doing an update:

- config/application.rb
- config/environments/{development|test|production}.rb
- All the default [initializers](https://github.com/rails/rails/tree/master/railties/lib/rails/generators/rails/app/templates/config/initializers) that you already have a copy of. I go back and forth on also opting some of these out, specifically `assets.rb`, `filter_parameter_logging.rb`, and `inflections.rb` which seem pretty likely to have been changed.
- All the default [binstubs](https://github.com/rails/rails/tree/master/railties/lib/rails/generators/rails/app/templates/bin) that you already have a copy of. I decided to still make the user review these, as bugs here are going to be annoying to debug, but it is good to use the latest versions if possible.
2021-02-09 12:20:56 -07:00
Vipul A M d9b286bf8a
Merge pull request #40441 from olivierlacan/doc/update-has-secure-password
Update outdated has_secure_password documentation [ci skip]
2021-02-09 01:34:12 +05:30
Rafael França d1416362e6
Merge pull request #41325 from damiann/damiann/autoload_grammar_fix
Fixing grammar in autoloading_and_reloading_constants [ci-skip]
2021-02-08 14:36:23 -05:00
Vipul A M b1f1879a50
Merge pull request #40995 from garrettdimon/patch-1
Add note for ActionText models that use UUID's [ci skip]
2021-02-08 12:03:28 +05:30
Ricardo Díaz 6af2355203 Use native Range#cover? which accepts Range arguments since Ruby 2.6
Commit: 9ca7389272
Discussion: https://bugs.ruby-lang.org/issues/14473

It seems to be compatible with the original ActiveSupport's
implementation, at least based on the test suite.

It also works faster:

```
Warming up --------------------------------------
 Ruby's Range#cover?     1.196M i/100ms
ActiveSupport's Range#cover?
                       396.369k i/100ms
Calculating -------------------------------------
 Ruby's Range#cover?     11.889M (± 1.7%) i/s -     59.820M in   5.033066s
ActiveSupport's Range#cover?
                          3.951M (± 1.2%) i/s -     19.818M in   5.017176s

Comparison:
 Ruby's Range#cover?: 11888979.3 i/s
ActiveSupport's Range#cover?:  3950671.0 i/s - 3.01x  (± 0.00) slower
```

Benchmark script:

```ruby
require "minitest/autorun"
require "benchmark/ips"

module ActiveSupportRange
  def active_support_cover?(value)
    if value.is_a?(::Range)
      is_backwards_op = value.exclude_end? ? :>= : :>
      return false if value.begin && value.end && value.begin.public_send(is_backwards_op, value.end)
      # 1...10 covers 1..9 but it does not cover 1..10.
      # 1..10 covers 1...11 but it does not cover 1...12.
      operator = exclude_end? && !value.exclude_end? ? :< : :<=
      value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
      cover?(value.first) && (self.end.nil? || value_max.public_send(operator, last))
    else
      cover?
    end
  end
end

class BugTest < Minitest::Test
  def test_range_cover
    Range.prepend(ActiveSupportRange)

    range = (1..10000)

    Benchmark.ips do |x|
      x.report("Ruby's Range#cover?") do
        range.cover?((100..20))
      end

      x.report("ActiveSupport's Range#cover?") do
        range.active_support_cover?((100..20))
      end

      x.compare!
    end
  end
end
```
2021-02-07 22:21:17 -05:00
Vipul A M 99c1112b42
Some grammar passes around guides [ci skip] (#41358) 2021-02-07 00:42:51 +05:30
Vipul A M d6d3fe6fa0
Merge pull request #40724 from clayton-shopify/fix-user-cookie-with-metadata-docs
Fix the documentation for use_cookies_with_metadata
2021-02-07 00:03:02 +05:30
Elias Saalmann 4ed3411ba8 Remove confirmations part of JavaScript guide since it causes confusion 2021-02-05 10:22:12 +01:00
Rafael Mendonça França 1b455e2e9d
Rails 6.2 is now Rails 7.0
We have big plans for the next version of Rails and that
require big versions.
2021-02-04 16:47:16 +00:00
Carlos Antonio da Silva bd9d7804e0 Fix Rails version typo in upgrading guide [ci skip] 2021-02-04 13:41:30 -03:00
Rafael Mendonça França 6487836af8
Rails 7 requires Ruby 2.7 and prefer Ruby 3+
The code cleanup is comming in later commits but this
already remove support to Ruby < 2.7.
2021-02-04 16:34:53 +00:00
Eileen M. Uchitelle 5a477890c8
Merge pull request #41258 from eileencodes/primary-class
Expose `primary_abstract_class` public API
2021-02-04 09:47:34 -05:00
Damian Nelson e6fd87bda8 Fix grammar for autoloading and reloading doc 2021-02-03 16:17:16 -08:00
Kasper Timm Hansen a1408e72f7
Merge branch 'main' into active_storage-named-variants 2021-01-29 03:25:37 +01:00
Rafael França 2ab5729c37
Merge pull request #41264 from ttilberg/patch-1
Clarify compilation notes [ci skip]
2021-01-28 16:00:28 -05:00
Gannon McGibbon f25ce1759d
Merge pull request #41259 from gmcgibbon/webpacker_guide_code_typos
Webpacker guide code typos
2021-01-28 11:46:17 -05:00
Tim Tilberg 0383551818
Clarify claim 2021-01-28 01:02:46 -06:00
st0012 34fcc5a566 Fix typo 2021-01-28 13:05:54 +08:00
Gannon McGibbon ead4fb3e61 [ci-skip] bundle exec rails -> bin/rails in Webpacker guide 2021-01-27 17:14:32 -05:00
Gannon McGibbon f2f1c8f56f [ci-skip] javascript_link_tag -> javascript_include_tag in Webpacker guide 2021-01-27 17:14:11 -05:00
eileencodes 4144746d33
Expose `primary_abstract_class` public API
Previously Rails was treating `ApplicationRecord` as special in the
`primary_class?` check. The reason we need to treat it differtently than
other connection classes is that `ActiveRecord::Base` will establish a
connection to the primary database on boot. The established connection
is to your primary database, or the first database defined in your
configuration. We need to do this so that 2 connections aren't opened to
the same database since `ActiveRecord::Base` and `AppliationRecord`
are different classes, on connection the connection_speicification_name
would be different.

However, there is no guarantee that an application is using
`ApplicationRecord` as it's primary abstract class. This exposes a
public method for setting a class to a `primary_abstract_class` like
this:

```
class PrimaryApplicationRecord < ActiveRecord::Base
  self.primary_abstract_class
end
```

Calling `primary_abstract_class` will automatically set
`self.abstract_class = true`. This change is backwards compatible
because we weren't supporting multiple application records previously,
and if you had an `ApplicationRecord` we assumed that was the primary
class. This change continues to assume that `ApplicationRecord` is your
primary class. You only need to set `primary_abstract_class` if your
application record is not ApplicationRecord and you're using multiple
databases.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2021-01-27 15:01:59 -05:00
Rafael Mendonça França 033706b2dc
Rename the config to make clear it is a boolean 2021-01-27 00:31:16 +00:00
Rafael Mendonça França 03cc18f5e7
Add config.action_view.stylesheet_media_default to baseline config 2021-01-27 00:28:56 +00:00
Rafael Mendonça França 8405513071
`ActionDispatch::Request#content_type` now returned Content-Type header as it is 2021-01-27 00:28:54 +00:00
Rafael França b623ee988c
Merge pull request #41215 from andrehjr/remove-legacy-media-screen
Remove legacy default media=screen from stylesheet_link_tag
2021-01-26 19:06:58 -05:00
Gannon McGibbon 6143b1121f
Merge pull request #41226 from t27duck/missing_erb_in_webpacker_guide
Guides: Missing erb tags for stylesheet_pack_tag [ci skip]
2021-01-25 17:36:26 -05:00
Tony Drake a131b7f875 Guides: Remove unneeded statement about stylesheet_pack_tag [ci skip] 2021-01-25 16:45:27 -05:00
Gannon McGibbon f15f494127
Merge pull request #41165 from davidstosik/webpacker-nitpicks
Add cosmetic improvements to the Webpacker guide
2021-01-25 12:46:21 -05:00
David Stosik 31ad146c16 Add small improvements to the Webpacker guide
- fix typos like double spaces, accidental caps
- improve some HTML links by giving them a label
- etc
2021-01-25 16:31:20 +09:00
Ryuta Kamizono c9effca029
Merge pull request #41228 from yboulkaid/remove-globalize
Remove reference to globalize gem from I18n guide

[ci skip]
2021-01-25 16:30:38 +09:00
Gannon McGibbon 76e37e29d8
Merge pull request #41220 from andrehjr/fix-generators-doc
Fix doc: stylesheet_include_tag -> stylesheet_link_tag
2021-01-25 02:00:39 -05:00
Youssef Boulkaid 46b8d343d3 Remove reference to globalize gem 2021-01-24 20:10:09 +01:00
Tony Drake 9182b90a58 Guides: Missing erb tags for stylesheet_pack_tag [ci skip]
The section on needing to use `stylesheet_pack_tag` was lacking the erb
%'s.

I updated the markdown to actually show the helper being used with erb
as well as improve the wording of the sentence.
2021-01-24 11:57:41 -05:00
Sean Doyle 0ad777cdcc
Improve ActionText::FixtureSet documentation (#41062)
* Improve ActionText::FixtureSet documentation

Support for Action Text attachments in fixtures was added by [76b33aa][] and
released as part of [6.1.1][], but has not yet been documented.

This commit documents the `ActionText::FixtureSet` for the API
documentation, and mentions it in the Rails Guides pages.

[76b33aa]: 76b33aa3d1
[6.1.1]: https://github.com/rails/rails/releases/tag/v6.1.1

* Fix indention of comments

Co-authored-by: David Heinemeier Hansson <david@loudthinking.com>
2021-01-24 11:16:27 +01:00
Sean Doyle c0f33b923b
Improve Fixture support for Active Storage (#41065)
* Improve Fixture support for Active Storage

Inspired by [76b33aa][], this commit extends the Active Storage
documentation to elaborate on how to declare fixtures.

In support of that, also introduce the `ActiveStorage::FixtureSet.blob`
method for injecting in-line [ActiveStorage::Blob][] attributes directly
into fixture YAML.

[76b33aa]: 76b33aa3d1
[ActiveStorage::Blob]: https://edgeapi.rubyonrails.org/classes/ActiveStorage/Blob.html

* Extra CR for style

* Two-space indention

* Explaining variable didn't explain, inline for style

Co-authored-by: David Heinemeier Hansson <david@loudthinking.com>
2021-01-24 11:10:30 +01:00
Chris Houhoulis a15b230fff Fix code block in Webpacker Guide [ci skip]
Formatting fix: the example directory tree listing was bleeding into the
previous paragraph and had extraneous characters due to a missing
newline.
2021-01-23 19:04:20 -05:00
André Luis Leal Cardoso Junior a141d741b1 Fix doc: stylesheet_include_tag -> stylesheet_link_tag 2021-01-23 13:07:58 -03:00