Commit Graph

9254 Commits

Author SHA1 Message Date
zzak f522f99f11
Set load_defaults to current Rails version in bug_report_templates
Currently only Action Mailbox and Active Storage use initialized apps, so at least in those cases we can ensure the correct defaults are used by bug reporters.
2023-10-31 17:54:35 +09:00
Sean Doyle 591d88aef4 Document Action Text Sanitization
Add documentation for `ActionText::RichText#to_s` and
`ActionText::Content#to_s` that demonstrates Action Text's ability to
sanitize and scrub its content.

Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-10-30 17:49:13 -04:00
Eileen M. Uchitelle 9483a19bcd
Merge pull request #49850 from ansonhoyt/document-active_record-strict_loading_violation_error
Improve `strict_loading` documentation [ci skip]
2023-10-30 14:48:43 -04:00
Anson Hoyt 51011701e3 Improve `strict_loading` documentation [ci skip]
* Update ActiveRecord::StrictLoadingViolationError API docs to
  reference the guide to help beginners learn how to resolve the error.
* Update Active Record Query Interface guide to cover configuration and
  the association option.

Apply suggestions from code review

Co-authored-by: Eileen M. Uchitelle <eileencodes@users.noreply.github.com>
2023-10-30 18:17:26 +00:00
Adrian Hirt 571f8a417c Update text for config.public_file_server.enabled [ci-skip]
Update the text for config.public_file_server.enabled in the configuring guide as PR #47137 turned on static file server by default for all environments.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-10-30 12:30:33 -05:00
Jean Boussier c28e4f2434 Use double quotes more consistenly in doc and error messages
For better or worse, the Rails guide settled on double quotes
and a large part of the community also use rubocop which enforce
them by default.

So we might as well try to follow that style when providing code
snippets in the documentation or error messages.

Fix: https://github.com/rails/rails/issues/49822

I certainly didn't get them all, but consistency should be significantly
improved.
2023-10-28 11:38:49 +02:00
Yasuo Honda 6c63b9b090
Merge pull request #49187 from ccutrer/defer-constraints
Add `set_constraints` helper for PostgreSQL
2023-10-28 14:40:24 +09:00
Rafael Mendonça França 421df52bf8
Merge pull request #49760 from akhilgkrishnan/remove-broken-link
Remove rails guides translation references [ci skip]
2023-10-27 17:23:28 -04:00
Rafael Mendonça França 403447d061
Use version of importmap that support loading outside of an app
We are using it in a few scripts, and we were doing workarounds
to be able to use outside an Rails application.

Now the workaround is gone.
2023-10-27 20:23:42 +00:00
Akhil G Krishnan b3aaa58d18 Remove rails guides translation references [ci skip] 2023-10-27 21:32:23 +05:30
Earlopain 19fea569b9
Remove note about inline changelog credit in contributing guide
[ci-skip]
2023-10-26 14:48:31 +02:00
mguan2020 afa59c3386 Add link providing more details about ERB in the 'Getting Started' documentation [ci skip]
Co-Authored-By: Akhil G Krishnan <akhilgkrishnan4u@gmail.com>

Add link providing more details about ERB in the 'Getting Started' documentation [ci skip]

Co-Authored-By: Akhil G Krishnan <akhilgkrishnan4u@gmail.com>

Fix link to point to html [ci skip]

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>

Revert "Merge branch 'branch_new' of https://github.com/mguan2020/rails into pr/49640"

This reverts commit 94b8c7d579a74c528c4a85f3ce0f0853c4883fd1, reversing
changes made to 1353ca902f260dfb9bbe7680ede2650a670f659f.

Revert "Revert "Merge branch 'branch_new' of https://github.com/mguan2020/rails into pr/49640""

This reverts commit e9ced85c8f6afe0bc057bc6d8d4387718a7c3916.
2023-10-25 21:04:26 +00:00
Steve Polito ef299a5656 Replace `:disabled` with `nil`
If there's a column named `disabled`, we'll still raise
`ActiveRecord::SubclassNotFound`. Setting `inheritance_column` to `nil`
works though.

I had mistakenly thought `:disabled` was the correct way to disable STI,
since this is what is done in [some tests][].

```ruby
Schema: cogs[ id, type, disabled, created_at, updated_at ]

class Cog < ApplicationRecord
  self.inheritance_column = nil
end

Cog.create! type: "Sprocket", disabled: true
=> #<Cog type: "Sprocket", disabled: "t">
```

[some tests]: a4751751bc/activerecord/test/models/post.rb (L231)
2023-10-25 13:36:57 -04:00
Steve Polito fcc000ce14 Improve STI documentation
Add new sections to [STI Guides][] demonstrating how to override or
disable the [inheritance_column][].

Also improve error message when `ActiveRecord::SubclassNotFound` is
raised.

[STI Guides]: https://guides.rubyonrails.org/association_basics.html#single-table-inheritance-sti
[inheritance_column]: https://api.rubyonrails.org/classes/ActiveRecord/ModelSchema.html#method-c-inheritance_column
2023-10-25 13:24:46 -04:00
Adrianna Chang 02fa5c2288
Merge pull request #49712 from MatheusRich/mr/docs-for-action-mailer-asset-host
[ci skip] Update Action Mailer guide on how to add images
2023-10-25 09:37:36 -04:00
Matheus Richard f18e3d382a Update Action Mailer guide on how to add images
Unlike controllers, mailers can't infer the protocol from the request,
so users need to specify it.
2023-10-25 10:25:59 -03:00
Cody Cutrer f9fee1a3cb Add `set_constraints` helper for PostgreSQL
The docs already talk about how to set up deferrable constraints, but
then rely on the user crafting custom SQL to actually use the feature.
The helper makes it easier to handle juggling multiple specific
constraints and quoting issues.
2023-10-24 11:49:11 -06:00
Mathieu Le Tiec 796eb66445
Clarify ActiveModel::SecurePassword maximum password length
Since 74264f4 improved the secure_password length validation to match bcrypt limit, this validation can be described more accurately in the ActiveModel basics guide.
2023-10-24 10:24:38 +02:00
Rafael Mendonça França 7937092b3e
Merge pull request #49723 from mylesboone/activestorage_touch_config
Add config option to not touch records
2023-10-23 13:56:02 -04:00
Petrik de Heus 2a5666ae11
Merge pull request #49729 from joshuay03/add-discord-link-to-contributing-guide
Add Discord invite link to contributing guide
2023-10-21 14:03:05 +02:00
Xinqi Mu 6dd1f87e26
Fix factually incorrect SQL statements 2023-10-21 18:40:45 +08:00
Joshua Young 1fb96f0856 Add Discord invite link to contributing guide 2023-10-21 16:14:17 +10:00
Hartley McGuire 92fb75e46a
Add release note for alias_attribute deprecation
Ref eae26caec3
2023-10-20 18:49:09 -04:00
Di Wu f48c3ad9e8
Update broken links in testing.md on Setting Header And CGI Variables (#49725)
* Update broken links in testing.md

The HTTP headers and CGI variables section had broken links. Updated these to direct to the correct locations on datatracker.ietf.org.

* Update to Point to correct section 4.1
2023-10-20 17:59:02 -04:00
Myles Boone 13d66b1632 Add config option to not touch records
ActiveStorage::Attachment records are not directly maintained by
ActiveStorage and it may not be feasible or desired to update the record
when its attachment is saved.
2023-10-20 14:41:57 -04:00
Aitor García Rey 4a3e51a840
Update classic_to_zeitwerk_howto.md
Some typos were fixed on the Zeitwerk migration guide.
2023-10-17 18:54:58 +02:00
Sean Doyle 8ecbdb3dbc Fix failing linter in `guides/source`
Fix [Failing CI Lint][]

Adds a missing comma to make an example Ruby block syntactically valid.

[Failing CI Lint]: https://github.com/rails/rails/actions/runs/6539678344/job/17758241844?pr=49486#step:4:12
2023-10-16 23:00:58 +01:00
eileencodes 0b1a6d76ac
[ci skip] Fix shard docs followup
Oops, the ShardRecord needs to be an abstract class and
ApplicationRecord needs to be a primary_abstract_class
2023-10-16 17:09:46 -04:00
eileencodes 35e0ae4337
[ci skip] Fix shard docs
We never explained how migrations paths work for shards. This fixes that
and also adds the appropriate class setup. You no longer need to set a
`default` shard as of #48353. In addition, `ApplicationRecord` should be
used for the non-sharded db that also serves as the tenant/shard router.
Then shards should get their own connection class since the schema
differs.
2023-10-16 17:02:11 -04:00
Rafael Mendonça França 2872d55a3b
Revert "Add psych to the bug report template"
This reverts commit e4e242685e.

This doesn't solve the problem.
2023-10-16 15:26:13 +00:00
Rafael Mendonça França e4e242685e
Add psych to the bug report template
With release of psych 5.1.1.1 bundler doesn't know which version to
load.

https://buildkite.com/rails/rails/builds/100852
2023-10-16 14:14:21 +00:00
Ryuta Kamizono 53438e9216
Merge pull request #49632 from zzak/bug_report_templates/unfreeze_rack
Revert "Freeze rack in 2.0 for guides bug report templates"
2023-10-15 12:40:51 +09:00
Dustin Brown c11c5cb482 Fix code blocks that caused lint failures 2023-10-14 17:02:19 +00:00
Rafael Montas dd8f6e5cbb Fix typo in configuring guide 2023-10-14 12:59:35 +00:00
zzak a03200460e
Revert "Freeze rack in 2.0 for guides bug report templates"
This reverts commit c5ace249e7.

Since this commit support for Rack 3 has stabilized.
2023-10-14 09:23:28 +09:00
Rafael Mendonça França 653725ee7c
Merge pull request #49610 from ezekg/fix/note-on-rails-7-1-sha-1-bug
Add note on active_record.encryption.support_sha1_for_non_deterministic_encryption
2023-10-13 17:14:47 +02:00
Edward Tippett 2130d523b4 Use correct tense of `cast` for guides
Switch to `cast` for describing the past tense actions.

`casted` is a common mistake, but not correct English.
2023-10-13 13:07:07 +10:30
paulreece f5668a0b18 Just clarifies a little the bun installation process and gives people instructions what to do if it did not install. 2023-10-12 18:01:38 -04:00
Zeke Gabrielse 88ed242498 Add note on support_sha1_for_non_deterministic_encryption 2023-10-12 14:37:30 -05:00
Carlos Antonio da Silva bbf4fc9efb
Merge pull request #49603 from y0608/patch-1
Fix broken link in AR validations guide [ci skip]
2023-10-12 10:44:16 -03:00
Carlos Antonio da Silva 837b8d992c
Merge pull request #49602 from Earlopain/49600-followup
Update filter_parameters default in configuring guide [ci skip]
2023-10-12 10:40:59 -03:00
Y.I bb638b4143
Typo: broken link 2023-10-12 16:30:14 +03:00
Earlopain 227aa4e8c0
Update filter_parameters default in configuring guide [ci skip] 2023-10-12 14:45:55 +02:00
Carlos Antonio da Silva 5103ab167e Fix numbered list and indentation of code blocks on upgrade guide
Otherwise they are considered separate lists instead of a sequence
within the same list. This also renders the code block with extra
indent, as part of the item they belong to.

Also use `Active Record Encryption` with capital letters consistently.

[ci skip]
2023-10-12 08:46:39 -03:00
Jonathan Hefner d7aee014cb Fix monospace formatting [ci-skip] 2023-10-11 23:51:34 -05:00
Jonathan Hefner 5021b46396 Remove unnecessary monospace formatting [ci-skip] 2023-10-11 23:47:52 -05:00
John Bampton 6cd5254111 guides/source/asset_pipeline.md: fix spelling 2023-10-12 13:54:00 +10:00
Rafael Mendonça França 90a6f3663b
Merge pull request #49587 from jdelStrother/patch-2
Advise upgraders to set active_record.encryption.hash_digest_class
2023-10-12 01:12:36 +02:00
Jonathan del Strother 5f68493cda
Advise upgraders to set active_record.encryption.hash_digest_class
This is currently documented in new_framework_defaults, but deserves highlighting more explicitly to help anyone upgrading from older versions.
2023-10-11 22:51:59 +00:00
Rafael Mendonça França 7228da34b9
Merge pull request #49532 from akhilgkrishnan/base-template-for-7-2-release-note
Added base template for rails 7.2 release note [skip ci]
2023-10-11 23:03:13 +02:00
Rafael Mendonça França 2f853e6bed
Merge pull request #49585 from akhilgkrishnan/update-7-1-to-7-2
Updated the rails version in 7.1 to 7.2 in guide [skip ci]
2023-10-11 22:01:30 +02:00
Carlos Antonio da Silva c8c95f424e
Merge pull request #49580 from p8/guides/format-html-attributes
Recommend fixed-width fonts for HTML and CSS as well in documentation [ci-skip]
2023-10-11 14:23:27 -03:00
Rafael Mendonça França 452c9f6c71
Merge pull request #49538 from akhilgkrishnan/capitalize-framework-names
Capitalize framework names [skip ci]
2023-10-11 17:04:27 +02:00
Akhil G Krishnan 41e86d4286 Updated the rails version in 7.1 to 7.2 in guide [skip ci] 2023-10-11 20:26:23 +05:30
Eileen M. Uchitelle bfd981ebb4
Merge pull request #49539 from akhilgkrishnan/docs-update-7-0-to-7-1
Updated the rails version in 7.0 to 7.1 in guide [skip ci]
2023-10-11 10:17:44 -04:00
Akhil G Krishnan 72fae17f92 Updated the rails version in 7.0 to 7.1 in guide [skip ci] 2023-10-11 19:45:22 +05:30
Ryuta Kamizono 7514031eeb
Merge pull request #49582 from fatkodima/enable-RedundantDoubleSplatHashBraces-cop
Enable `Style/RedundantDoubleSplatHashBraces` rubocop cop
2023-10-11 22:39:55 +09:00
fatkodima b8829cabec Enable `Style/RedundantDoubleSplatHashBraces` rubocop cop 2023-10-11 14:55:00 +03:00
hachi8833 0df2c25479 Update guide: NPM -> npm 2023-10-11 19:07:50 +09:00
Petrik 79f5588d33 Recommend fixed-width fonts for HTML and CSS as well in docs [ci-skip] 2023-10-11 11:20:11 +02:00
Sébastien Dubois 6eeb128e60 Explain how to configure collection cache key 2023-10-11 09:54:54 +02:00
Jonathan Hefner 8776e951f2
Merge pull request #49556 from mguan2020/my_new_branch
Fixed formatting in Action Text documentation to make it more consistent. [ci skip]
2023-10-10 23:06:26 -05:00
John Bampton 7ee9306bb7 guides/source/asset_pipeline.md: change `Javascript` to `JavaScript` 2023-10-11 09:18:36 +05:30
John Bampton bc41113fc9 guides/source/configuring.md: fix grammar and spelling 2023-10-11 09:18:36 +05:30
Akhil G Krishnan cf61804fd4 Update postgres naming to PostgreSQL 2023-10-11 09:18:36 +05:30
John Bampton 10bd1d8d23 guides/source/asset_pipeline.md: change `Javascript` to `JavaScript` 2023-10-11 08:13:16 +10:00
John Bampton ecac7d6d4e guides/source/configuring.md: fix grammar and spelling 2023-10-11 07:04:34 +10:00
Carlos Antonio da Silva c7e3cf2561
Merge pull request #49562 from akhilgkrishnan/update-postgres-naming-to-postgresql
Update postgres naming to PostgreSQL
2023-10-10 15:51:45 -03:00
hachi8833 4d4f80d2c1 Update raise_on_open_redirects config with table style 2023-10-10 19:38:10 +09:00
Akhil G Krishnan 80a5fb50c2 Update postgres naming to PostgreSQL 2023-10-10 13:44:20 +05:30
hachi8833 8763271aef Add raise_on_missing_callback_actions to configuring guide 2023-10-10 11:22:10 +09:00
mguan2020 643484922d Fixed formatting of 'contenteditable' and 'execCommand' in the Action Text guide to make it more consistent with the rest of the documentation.
Detail:
This Pull Request modifies the documentation of Action Text so that all instances of 'contenteditable' and 'execCommand' are now in a code block. This makes the documentation more readable for users.
2023-10-09 22:34:08 +00:00
Xavier Noria 785b2c29cd Fix example in Active Storage guide
url_for returns a URL, not a path. Also, as the text says,
that URL points to the redirect controller, the "/redirect"
segment was missing.
2023-10-09 17:17:28 +02:00
Akhil G Krishnan 73b2ae04fe Point to Guide instead of edge [skip ci] 2023-10-09 19:58:56 +05:30
Carlos Antonio da Silva e3e0c646ab Point to API docs instead of edge [ci skip] 2023-10-09 10:19:38 -03:00
Akhil G Krishnan c96695dfcf Capitalize framework names 2023-10-08 11:34:21 +05:30
Hartley McGuire ce86940744
Update gem bug report templates to 7.1 2023-10-07 20:49:14 -04:00
fatkodima 961fc42f90
Merge pull request #49533 from akhilgkrishnan/release-note-typo-fix
Typo: Updated the rails version in rails 7.2 release note [skip ci]
2023-10-07 21:22:05 +03:00
Akhil G Krishnan 6df831a5c6 Typo: Updated the rails version in rails 7.2 release note [skip ci] 2023-10-07 23:12:40 +05:30
Akhil G Krishnan 8a67e18d6c Added base template for rails 7.2 release note [skip ci] 2023-10-07 23:05:53 +05:30
Jonathan Hefner ff191cebe5 Simplify up / down migration example [ci-skip]
Follow-up to #47782.

These examples merely illustrate the order of execution when using `up`
and `down`, so we only need one operation before and after.
2023-10-07 12:26:26 -05:00
Jonathan Hefner 400d9d498b Add missing caveats for migration #change actions [ci-skip] 2023-10-07 12:26:26 -05:00
Jonathan Hefner a89412b362 Remove redundant caveat for remove_column [ci-skip] 2023-10-07 12:26:26 -05:00
Jonathan Hefner 8d0748e6b0 Rewrite Testing Jobs section [ci-skip]
This simplifies the prose and code examples, and links to more API docs.
2023-10-07 12:26:26 -05:00
Jonathan Hefner ed08eea99f Capitalize framework names [ci-skip] 2023-10-07 12:26:26 -05:00
Jonathan Hefner 4c2fdbfac5 Move Server Timing info to Configuration guide [ci-skip]
Follow-up to #48221.

The Active Support Instrumentation guide is about the
`ActiveSupport::Notifications` API.  Therefore, move the information
about `config.server_timing` and the `ActionDispatch::ServerTiming`
middleware to the existing sections in the Configuration guide.
2023-10-07 12:26:21 -05:00
Jonathan Hefner 6df4d3b6ff Fix punctuation and formatting [ci-skip] 2023-10-07 12:02:23 -05:00
Jonathan Hefner 9418b34e7d Reword "Regarding the Rails Stack" section [ci-skip] 2023-10-07 12:02:23 -05:00
Jonathan Hefner ce019f1241 Reword "Method Visibility" section [ci-skip]
For clarity and brevity.
2023-10-07 12:02:23 -05:00
Jonathan Hefner eabc003f8e Link to api.rubyonrails.org instead of edgeapi [ci-skip] 2023-10-07 12:02:22 -05:00
Jonathan Hefner 76ef648858 Rewrap documentation example for legibility [ci-skip] 2023-10-07 12:02:22 -05:00
Jonathan Hefner 0e908bb5ef Use ruby code fence [ci-skip]
These examples show RDoc in the form of Ruby comments, and should
therefore use the `ruby` code fence (which matches the other examples in
this guide).
2023-10-07 12:02:22 -05:00
Jonathan Hefner 8447a72948 Convert examples from Markdown to RDoc [ci-skip]
This guide is about API documentation which uses RDoc, so we should
avoid Markdown syntax in examples.
2023-10-07 12:02:22 -05:00
Jonathan Hefner e8166c4c70 Hyphenate "database specific" [ci-skip]
"database-specific" is a compound adjective, and thus hyphenated.
2023-10-07 12:02:22 -05:00
Jonathan Hefner 29b32216ff Link to ActionDispatch::DebugExceptions API doc [ci-skip]
This also adds missing punctuation and formatting.
2023-10-07 11:55:35 -05:00
Jonathan Hefner 3534c40c33 Move example to API docs [ci-skip] 2023-10-07 11:55:34 -05:00
Jonathan Hefner d81019eb40 Link to API docs [ci-skip] 2023-10-07 11:52:34 -05:00
Edouard CHIN 8be0c10c48 Add doc to explain how to migrate to the new BroadcastLogger:
- This should make it easier for apps or libraries that were
  previously relying on the private API.
  Also took the opportunity to tweak the doc of the BroadcastLogger
  to mention what happens when calling a non-standard method.

  Fix #49494
2023-10-07 14:43:46 +02:00
hachi8833 232f237589 Update changelog links to 7-1-stable 2023-10-06 18:05:21 +09:00
Rafael Mendonça França 2d271a4b90
Merge pull request #49491 from tnir/tn-date-rails71
Add corrected release month for Rails 7.1
2023-10-05 08:01:36 +00:00
Rafael Mendonça França 2974362b3f
Add release month for Rails 7.1
We know we are going to release this month.
2023-10-05 07:59:58 +00:00
hachi8833 9c421dde8c Fix heading in migration guide 2023-10-04 20:20:10 +09:00
hachi8833 ffee8a0aa2 Add description for db:prepare
Review by ChatGPT

Minor fix on db:prepare document

Update by review

Add hard wrap
2023-10-04 19:04:09 +09:00
Sean Doyle bff95987ef Resolve Upgrading Rails lint violation
Follow-up to [#49474][]

Execute documentation change in CI so that the linters can scan the
documentation's code blocks.

[#49474]: https://github.com/rails/rails/pull/49474#issuecomment-1745519821
2023-10-03 14:42:13 -04:00
Petrik de Heus d7e401d752
Merge pull request #49474 from seanpdoyle/upgrading-action-view-rendered
Document how to upgrade to `ActionView::TestCase#rendered` [ci skip]
2023-10-03 20:20:27 +02:00
Sean Doyle 5243fd302b Document how to upgrade to `ActionView::TestCase#rendered` [ci skip]
Based on a [comment on #49194][], describe how to achieve backwards
compatibility with existing `ActionView::TestCase` definitions.

[comment on #49194]: https://github.com/rails/rails/pull/49194#discussion_r1337832295
2023-10-03 13:43:11 -04:00
Mateus Pereira 2b38f2b954 Change `resourceful` to `resource` for clarity 2023-10-03 10:28:28 -03:00
Steve Polito 96a9570a26 Update links in Generator Guides
Link to `Rails::Generators::Testing::Behavior` instead of
`Rails::Generators::Testing::Behaviour` in an effort to ensure the Edge
Guides link to the correct API documentation.
2023-10-03 09:27:33 -04:00
Steve Polito e659f46da1
Conditionally print `$stdout` when invoking `run_generator` (#49448)
* Conditionally print `$stdout` when invoking `run_generator`

In an effort to improve the developer experience when debugging
generator tests, we add the ability to conditionally print `$stdout`
instead of capturing it.

This allows for calls to `binding.irb` and `puts` work as expected.

```sh
PRINT_STDOUT=true ./bin/test test/generators/actions_test.rb
```

* Update railties/CHANGELOG.md

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>

* Rename environment variable

* Update generators guides.

* Update guides

---------

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2023-10-03 07:01:16 -04:00
Shozo Hatta b10a2e4943
[ci-skip][Docs]Add encryption.add_to_filter_parameters to configuring.md (#49443)
* Add encryption.add_to_filter_parameters to configuring.md

encryption.add_to_filter_paramters has been merged by https://github.com/rails/rails/pull/46453.

(This PR is a second try of https://github.com/rails/rails/pull/49364 )

* Update entry for encryption.add_to_filter_parameters

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2023-10-02 06:39:40 -04:00
Rafael Mendonça França a5f113f433
Merge pull request #49423 from paulreece/update_has_one_doc
Added available methods for has_one association to guide.
2023-09-29 16:24:07 -04:00
Rafael Mendonça França db2ef1d250
Merge pull request #49417 from Edouard-chin/ec-logger-fix
Fix the BroadcastLogger being initialized too late:
2023-09-29 15:45:03 -04:00
Rafael Mendonça França 098eea5be0
Merge pull request #49433 from bdewater/as-notifications-events
Stop building AS::Notifications::Event manually
2023-09-29 14:40:04 -04:00
Rafael Mendonça França 00dd041192
Those features are not merged yet 2023-09-29 18:29:53 +00:00
Bart de Water 95b6fbd00f Stop building AS::Notifications::Event manually
It's possible since Rails 6 (3ea2857943) to let the framework create Event objects, but the guides and docs weren't updated to lead with this example.

Manually instantiating an Event doesn't record CPU time and allocations, I've seen it more than once that people copy-pasting the example code get confused about these stats returning 0. The tests here show that - just like the apps I've worked on - the old pattern keeps getting copy-pasted.
2023-09-29 12:34:23 -04:00
Edouard CHIN 40cb50e06e Fix the BroadcastLogger being initialized too late:
- An oversight of #48615 is that it changes the `Rails.logger` to be
  a broadcast logger after the app is booted. Anything referencing
  `Rails.logger` during the boot process will get a simple logger and
  ultimately resulting in logs not being broadcasted.

  For example `ActionController::Base.logger.info("abc")` would
  just output logs in the `development.log` file, not on STDOUT.

  ----

  The only solution I could think of is to create a BroadcastLogger
  earlier at boot, and add logger to that broadcast when needed (instead
  of modiyfing the `Rails.logger` variable).
2023-09-29 15:42:47 +02:00
hachi8833 d41a5dad9a Add assert_error_reported and assert_no_error_reported to testing.md
See #46029.
2023-09-29 19:37:47 +09:00
Earlopain f3e0a72801
Fix formatting of two configs in configuration guide 2023-09-29 11:32:41 +02:00
paulreece 519558108e This adds the following methods to the definition of available methods in the guide:
belongs_to - foreign_type, :required, :default, :strict_loading, and :ensuring_owner_was .
has_one - :required, :disable_joins, :strict_loading, :query_constraints, and :ensuring_owner_was .
has_many - :disable_joins, :ensuring_owner_was, :extend, :foreign_type, :query_constraints, :strict_loading
has_and_belongs_to_many - :strict_loading .
2023-09-28 21:20:44 -04:00
Hartley McGuire b4d8603bd3
Merge pull request #49418 from akhilgkrishnan/html-to-erb
Fix the wrong markdown highlighting [skip ci]
2023-09-28 13:26:44 -04:00
Rafael Mendonça França 02313b836e
Merge pull request #49412 from fatkodima/fix-multiple-dbs-example
Enable raising when running `rubocop-md` against invalid ruby snippets
2023-09-28 11:54:39 -04:00
Akhil G Krishnan 2e35046f61 Fix the wrong markdown hightlighting [skip ci] 2023-09-28 20:14:35 +05:30
fatkodima a7ee313d91 Enable raising when running `rubocop-md` against invalid ruby snippets 2023-09-27 23:12:48 +03:00
Koichi ITO 3e14e8dd62 Add `async_ids` to 7_1_release_notes [ci skip]
This PR adds `async_ids` introduced at https://github.com/rails/rails/pull/46503
to 7_1_release_notes.
2023-09-27 23:32:44 +09:00
Rafael Mendonça França fb6c6007d0
Development of Rails 7.2 starts now
🎉
2023-09-27 03:59:11 +00:00
Rafael Mendonça França e57a936879
Merge pull request #49397 from hatsu38/fix_typo-author_name-in_md
[skip ci] Docs: Fix typo in author name Paul Coelho -> Paulo Coelho
2023-09-26 23:23:26 -04:00
Rafael Mendonça França e5386cb402
Preparing for 7.1.0.rc1 release 2023-09-27 03:08:31 +00:00
hatsu38 c0d8528b24 [skip ci] Docs: Fix typo in author name Paul Coelho -> Paulo Coelho 2023-09-27 12:00:55 +09:00
Rafael Mendonça França 7893e0a165
Merge pull request #49194 from seanpdoyle/action-view-test-case-encoder
Introduce `ActionView::TestCase.register_parser`
2023-09-26 22:30:25 -04:00
Sean Doyle 7badc42723
Introduce `ActionView::TestCase.register_parser`
Register a callable to decode rendered content for a given MIME type

Each registered decoder will also define a `#rendered.$MIME` helper
method, where `$MIME` corresponds to the value of the `mime` argument.

=== Arguments

`mime` - Symbol the MIME Type name for the rendered content
`callable` - Callable to decode the String. Accepts the String
                    value as its only argument
`block` - Block serves as the decoder when the
                 `callable` is omitted

By default, ActionView::TestCase defines a decoder for:

* :html - returns an instance of Nokogiri::XML::Node
* :json - returns an instance of ActiveSupport::HashWithIndifferentAccess

Each pre-registered decoder also defines a corresponding helper:

* :html - defines `rendered.html`
* :json - defines `rendered.json`

=== Examples

To parse the rendered content into RSS, register a call to `RSS::Parser.parse`:

```ruby
register_decoder :rss, -> rendered { RSS::Parser.parse(rendered) }

test "renders RSS" do
  article = Article.create!(title: "Hello, world")

  render formats: :rss, partial: article

  assert_equal "Hello, world", rendered.rss.items.last.title
end
```

To parse the rendered content into a Capybara::Simple::Node,
re-register an `:html` decoder with a call to
`Capybara.string`:

```ruby
register_decoder :html, -> rendered { Capybara.string(rendered) }

test "renders HTML" do
  article = Article.create!(title: "Hello, world")

  render partial: article

  rendered.html.assert_css "h1", text: "Hello, world"
end
```
2023-09-27 02:03:23 +00:00
Rafael Mendonça França acfa045405
Revert typography change in user facing errors
This change would force a lot of existing applications and libraries
to update their tests.

We included it in the beta to collect feedback from the community and
we had some comments about how negative this change would be.

Developers that care about the typography of their error messages
can easily change it in their applications using the translation
files, so there is no need to inflict pain in the upgrade process
by changing the default in the framework.

Revert "Merge PR #45463"

This reverts commit 9f60cd8dc7, reversing
changes made to 35d574dbfd.
2023-09-26 21:45:03 +00:00
Ryuta Kamizono 1fe4538635 Fix `rewhere`'s link for API doc in the guide
This was accidentally changed at #47010.
2023-09-27 02:43:22 +09:00
Akhil G Krishnan 2022ee1be5 [skip ci] ActiveRecord notable changes added to 7.1 release note 2023-09-26 22:54:46 +05:30
Rafael Mendonça França dcc6ad5497
Merge pull request #49370 from ghiculescu/upgrade-guide-rails-test
Upgrade guide: mention `test:prepare` enhnacements
2023-09-26 12:22:16 -04:00
Rafael Mendonça França 15ccf5be96
Merge pull request #49387 from fractaledmind/ar-sqlite-7_1-release-notes
[skip ci] Add 7.1 release notes for SQLite3 adapter improvements
2023-09-26 12:03:13 -04:00
Stephen Margheim 8c5584cf07 Add 7.1 release notes for SQLite3 adapter improvements 2023-09-26 16:09:05 +02:00
zzak a564341537
Revert "Document clean chain behavior for ActiveRecord scope" 2023-09-26 20:44:22 +09:00
Ryuta Kamizono b2790b6680 Rename back unique keys to unique constraints
As we (I and @yahonda) talked about the naming in person, naming unique
constraints as unique keys is very confusing to me.
All documents and descriptions says it's unique constraints, but naming
unique keys leads to misunderstanding it's a short-hand of unique
indexes.
Just naming it unique constraints is not misleading.
2023-09-26 17:52:09 +09:00
Rafael Mendonça França ad7a3e2d80
Merge pull request #49322 from hachi8833/add_tests_for_exclusion_validation2
[Docs][Tests] Add tests for validates_exclusion_of to 7.1.0beta1
2023-09-25 16:26:58 -04:00
Akhil G Krishnan 14208d4d53 [skip ci] Missing language highligting added for bash code block 2023-09-25 21:25:33 +05:30
Xavier Noria 44d0859904 Minor edits in the upgrading guide 2023-09-25 11:45:47 +02:00
Alex 9910e37e6f Upgrade guide: mention `test:prepare` enhnacements
Fixes: https://github.com/rails/rails/issues/49363

Mentions https://github.com/rails/rails/pull/46664 in the upgrade guide.
2023-09-25 10:04:30 +10:00
Xavier Noria d99e355390 Simplify wording, avoids word wrap 2023-09-24 09:08:01 +02:00
Xavier Noria 72bd066432 Add a section about config.autoload_lib(_once) to the upgrading guide 2023-09-23 20:15:34 +02:00
Xavier Noria a7fa54d5d8 Minor reword in the upgrading guide re add_autoload_paths_to_load_path 2023-09-23 19:29:11 +02:00
Akhil G Krishnan 102eb1f0b6 ActiveRecord notable changes added to 7.1 release note
[skip ci] review changes updated
2023-09-23 20:38:45 +05:30
Xavier Noria 26d24d6dc3 Let these example match the ones in config/application.rb 2023-09-21 21:20:23 +02:00
Xavier Noria 8eed5083b7 Reword stuff related to config.autoload_lib 2023-09-21 21:14:03 +02:00
hachi8833 4fb4af7312 [Docs][Tests] Add tests for validates_exclusion_of to 7.1.0beta1 Active Model 2023-09-21 10:33:58 +09:00
Petrik 677fa58873 Improve `strict_loading` documentation [ci-skip]
Expand examples by adding singular associations.
Expand the guides with `strict_loading!`.
Also add `to_a` to code examples as loading the associations is required
to raise the errors.
2023-09-20 13:54:32 +02:00
Adrianna Chang e1d160d0ba
Remove blank line in Action Mailer Basics guide 2023-09-19 15:02:20 -04:00
Anson Hoyt 19c996f763
Add `*_deliver` callback examples [ci skip]
Examples based on the conversation in https://github.com/rails/rails/pull/47630.
2023-09-19 10:47:16 -04:00
Petrik de Heus ebcd7233ea
Merge pull request #49313 from tnir/tn-replace-firebug-in-security-guides [ci-skip]
doc: Firebug was replaced by Firefox/Chrome DevTools
2023-09-18 19:36:53 +02:00
Takuya Noguchi f8e1e20341 Firebug was replaced by Firefox/Chrome DevTools
https://getfirebug.com/index.html
https://hacks.mozilla.org/2017/10/saying-goodbye-to-firebug/
https://firefox-source-docs.mozilla.org/devtools-user/
https://developer.chrome.com/docs/devtools/

Signed-off-by: Takuya Noguchi <takninnovationresearch@gmail.com>
2023-09-19 00:26:43 +09:00
Sean Doyle 8b77436dbc Add documentation for `locals:` and `local_assigns` [ci skip]
Expand the documentation for [local_assigns][] to mention potential
integrations with [Ruby 3.1's pattern matching
assignment][pattern-matching].

Expand the Action View Overview guides to describe calls to `render`
with `locals:` options, along with the existence of the `local_assigns`
method. Also outline potential integrations with Ruby 3.1's pattern
matching assignment.

[local_assigns]: https://api.rubyonrails.org/classes/ActionView/Template.html#method-i-local_assigns
[pattern-matching]: https://docs.ruby-lang.org/en/master/syntax/pattern_matching_rdoc.html
2023-09-18 08:31:03 -04:00
Hartley McGuire d21d811ffe
Merge pull request #49291 from hungmi/fix-typos-in-action-view-test-case-documentation
[ci skip] Edit anchors in Testing View Partials to match targets
2023-09-15 14:05:27 -04:00
Nick Schwaderer a50be005ae
Update 7_1_release_notes.md (#49285)
* Update 7_1_release_notes.md

For context see https://github.com/rails/rails/pull/45867

Include in release notes the deprecation of `true` and `false` values
for `config.action_dispatch.show_exceptions` in favor of `:all`,
`:rescuable` and `:none`.

* Update 7_1_release_notes.md

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>

---------

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2023-09-15 13:52:51 -04:00
hungmi f4234474e0 Edit anchors in Testing View Partials to match targets 2023-09-16 01:45:15 +08:00
Rafael Mendonça França 3c8e3fe37f
Merge pull request #49288 from seanpdoyle/action-view-guides-shared-partials
Action View: docs use `application/` instead of `shared/`
2023-09-15 13:05:18 -04:00
Rafael Mendonça França 19930b4c63
Merge pull request #49276 from akhilgkrishnan/add-railties-notable
Added new railties notable changes in 7.1 release note [skip ci]
2023-09-15 12:12:12 -04:00
Rafael Mendonça França 93ea1d0219
Merge pull request #49289 from esasse/remove-mispell-docs
Remove misspell references [ci skip]
2023-09-15 12:11:24 -04:00
Sean Doyle 32faee0e52 Action View: docs use `application/` instead of `shared/`
Change mentions of `app/views/shared` in the guides to be
`app/views/application` instead. View partials rely on the same
[Template Inheritance][] as their template counterparts, so the guides
should encourage end-users to benefit from that inheritance.

> This makes `app/views/application/` a great place for your shared
> partials, which can then be rendered in your ERB as such:
>

```html+erb
<%# app/views/admin/products/index.html.erb %>
<%= render @products || "empty_list" %>

<%# app/views/application/_empty_list.html.erb %>
There are no items in this list <em>yet</em>.
```

To enforce that template resolution, this commit also replaces
references to `shared/` with `application/` in the Rails test suite.

[Template Inheritance]: https://guides.rubyonrails.org/layouts_and_rendering.html#template-inheritance
2023-09-15 12:06:22 -04:00
Erick Sasse 7c2e4fc5eb Remove misspell references 2023-09-15 16:02:54 +00:00
Alex Ghiculescu ccde530867 Shorten some of the guide names in the Guides index 2023-09-15 07:52:59 +10:00
Akhil G Krishnan 524f485d9e
Added new railties notable changes in 7.1 release note 2023-09-14 17:35:52 +00:00
Akhil G Krishnan 96ff4767bf
Add missing dollar sign to bash scripts 2023-09-14 16:55:46 +00:00
Eileen M. Uchitelle ff309346d3
Merge pull request #49268 from ghiculescu/cpk-guide
Add Composite Primary Keys guide to guides index
2023-09-14 11:39:14 -04:00
Alex 25524826aa Add Composite Primary Keys guide to guides index 2023-09-14 12:32:33 +10:00
Sean Doyle a92bc713ee
Update guides/source/testing.md
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
2023-09-13 10:18:52 -04:00
Sean Doyle a9148b45f3 Add "Testing View Partials" section to the Testing Guides
Motivation / Background
---

While the `ActionView::TestCase` class isn't marked with a `:nodoc:`
comment to indicate that it's internal to Rails, there isn't much
content in the guides that explains how to test view partials.

Libraries like
[view_component](https://github.com/ViewComponent/view_component/) have
[built-in support for
testing](https://viewcomponent.org/guide/testing.html), including
Capybara integration.

While `ActionView::TestCase` already integrates with
`rails-dom-testing`, that integration could be better documented.
Additionally, it wouldn't take much for consuming applications to mimic
the ViewComponent testing experience for their Action View Partials.

Details
---

First, link to the "Testing Rails Applications" page from the
`ActionView::TestCase` class documentation.

Next, add a "Testing View Partials" section to the guides that expands
upon the variety of tooling available to tests that inherit from
`ActionView::TestCase`. In that section, cover topics like:

* the `render` helper method
* the `rendered` helper attribute reader
* calls to `assert_select` with attribute placeholders
* the `document_root_element` helper method
* integration with Ruby's Pattern Matching
* opportunities to integrate with Capybara

Additional Information
---

Additionally, add test coverage that exercise the examples shared in the
new section, including:

* Calls to `assert_select` that utilize attribute placeholders
* Ruby 3.0's Pattern Matching
* Integration with Capybara
2023-09-13 09:44:44 -04:00
Rafael Mendonça França 699dfdb426
Preparing for 7.1.0.beta1 release 2023-09-13 00:36:01 +00:00
Jason Meller 274bc97d63
Add Bun support (#49241)
* Add Bun support to `rails new -j` generator

* Add additional generation consideration for Bun

* Use development gems to test the whole workflow

* Remove custom gems from local testing

* Revert lock

* Revert errant custom gem declaration

* Fix linting errors

* Fix remnants of bad merge

* Always use latest bun

* Update actioncable/lib/rails/generators/channel/channel_generator.rb

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>

* Update guides/source/working_with_javascript_in_rails.md

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>

* Only use the latest bun if nothing is specified

* Hardcode known good version

---------

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2023-09-12 16:55:27 -04:00
Rafael Mendonça França 15c639fab2
Active Job, not ActiveJob 2023-09-12 01:15:37 +00:00
Rafael Mendonça França 1b97206dd3
Revert "Remove AbstractController::Translation.raise_on_missing_translations added to release note [skip ci]" (#49221) 2023-09-11 11:44:04 -04:00
Eileen M. Uchitelle 450f64d595
Merge pull request #49219 from Shopify/AR-supports-non-PK-column-named-id
Rails supports but does not recommend non-PK `id` column
2023-09-11 11:20:50 -04:00
Adrianna Chang 4cfb6d0111
[ci skip] Fix typo in association guides 2023-09-11 10:51:15 -04:00
Nikita Vasilevsky 6100664a41
Rails supports but does not recommend non-PK `id` column 2023-09-11 14:28:14 +00:00
Eileen M. Uchitelle 0bddf3513b
Merge pull request #49218 from Shopify/suggest-cpk-for-join-tables
[ci skip] Suggest using composite primary key on join tables in `:through` associations
2023-09-11 10:24:21 -04:00
Nikita Vasilevsky 5f69951cf2
Suggest using composite primary key on join tables in `:through` associations 2023-09-11 14:19:01 +00:00
Ryuta Kamizono bb4dbd14f8
Merge pull request #49213 from akhilgkrishnan/action-config-removal-release-note
Remove AbstractController::Translation.raise_on_missing_translations added to release note [skip ci]
2023-09-11 15:26:27 +09:00
Jonathan Hefner 43a9e05dc4 Describe AS::MessagePack in 7.1 release notes [ci-skip]
This covers #47770, #47964, #48103, and #48104, plus the follow-up
changes to `ActiveSupport::Cache::Store` options from #48449 and #48451.
2023-09-10 17:52:55 -05:00
Jonathan Hefner 659d378b21 Tweak summary of `generates_token_for` in CHANGELOG [ci-skip] 2023-09-10 16:45:56 -05:00
Jonathan Hefner 38e388bbb8 Tweak summary of `normalizes` in CHANGELOG [ci-skip] 2023-09-10 16:44:21 -05:00
Jonathan Hefner 843283b4dd Add negative `where` examples for `normalizes`
In #49105, `where` examples were added to the `normalizes` documentation
to demonstrate that normalizations are also applied for `where`.
However, as with the `exists?` examples, we should also demonstrate that
normalizations are only applied to keyword arguments, not positional
arguments.  We can also address the original source of the confusion by
changing the wording of "finder methods" to "query methods".

This commit also removes the tests added in #49105.  `normalizes` works
at the level of attribute types, so there is no need to test every query
method.  Testing `find_by` is sufficient.  (And, in point of fact,
`find_by` is implemented in terms of `where`.)
2023-09-10 16:40:29 -05:00
Akhil G Krishnan a564e758c9
Remove Enumerable#sum from guide 2023-09-10 05:48:41 +00:00
Akhil G Krishnan f4c868ffbf
Remove AbstractController::Translation.raise_on_missing_translations added to release note 2023-09-10 05:10:48 +00:00
Alex Ghiculescu ff6881d2b2
Remove old `raise_on_missing_translations` behaviour
ref: https://github.com/rails/rails/pull/47105#issuecomment-1400843060

Removes the old `raise_on_missing_translations` accessors, that used to live [here](fee61e3abc/actionpack/lib/abstract_controller/translation.rb (L7)) and [here](5c835bd669/actionview/lib/action_view/helpers/translation_helper.rb (L15)).

Closes https://github.com/rails/rails/pull/45361
2023-09-09 19:59:49 +00:00
Ryuta Kamizono 97737abbeb Merge pull request #49201 from akhilgkrishnan/remove-webpacker-file
Remove unused webpacker related files
2023-09-09 07:44:54 +09:00
Adrianna Chang 2b7fb8fe4f
Add guide for composite primary keys
Co-authored-by: Noah Gibbs <noah.gibbs@shopify.com>
2023-09-08 13:55:34 -04:00
Eileen M. Uchitelle 8bea21ec32
Merge pull request #49186 from Shopify/migration_guide_cpk_create
[ci skip] Add a section to the Active Record Migration Guide on creating tables with composite primary keys
2023-09-08 08:48:33 -04:00
Noah Gibbs 5ee23cb845
Add a section on creating tables with composite primary keys 2023-09-08 13:37:28 +01:00
Noah Gibbs 0501555800
Note that guide text should wrap at 80 columns 2023-09-08 13:22:28 +01:00
Akhil G Krishnan cafad7a23a
Remove unused webpacker related files 2023-09-08 11:22:09 +00:00
Adrianna Chang 44bd6e7aca
Merge pull request #49182 from adrianna-chang-shopify/ac-document-associations-cpk-models
Document associations between models with composite primary keys in guides [ci skip]
2023-09-07 14:13:55 -04:00
Adrianna Chang 006b91719d
Merge pull request #49188 from adrianna-chang-shopify/ac-document-more-finder-methods-cpk
Add additional docs to Query Interface guide about composite primary key models [ci skip]
2023-09-07 14:12:46 -04:00
Adrianna Chang a6faf080fe
Document associations between models with composite primary keys in Rails guides 2023-09-07 14:11:05 -04:00
Adrianna Chang ed58ce03ee
Add additional docs to Query Interface guide about composite primary key models 2023-09-07 14:02:44 -04:00
Akhil G Krishnan 73eb8bccdd
[skip ci] Made a consistant wording accross the notes 2023-09-07 17:14:18 +00:00
Hartley McGuire 0851a878d3
Merge pull request #49170 from higher-pixels/delete-async
Improving the setup for the Active Record Encryption Guide
2023-09-07 11:28:36 -04:00
Adrianna Chang 9dc2288d64
Merge pull request #49179 from Shopify/cpk-release-notes
[ci skip] Add composite primary key release note
2023-09-07 10:49:57 -04:00
Nikita Vasilevsky 53e690e623
Add composite primary key release note 2023-09-07 14:42:55 +00:00
Tom Rossi 2ccc2c2fe2 Improving the Rails Guide around setting up Active Record Encryption 2023-09-07 08:09:14 -04:00
Akhil G Krishnan 61a9c1a92a Ruby code block indentation issue fix
[skip ci] indentation fix

[skip ci] review changes added

[skip ci] indentation fix
2023-09-07 01:14:48 +05:30
Akhil G Krishnan 7b8eadba02
[skip ci] ActiveSupport deprecate changes added to 7.1 release note (#49119)
* [skip ci] ActiveSupport deprecate changes added to 7.1 release note

* Update guides/source/7_1_release_notes.md

Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>

---------

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
2023-09-05 16:29:07 -04:00
Rafael Mendonça França e1cfcb1951
Fix indentation in 7.1 release notes 2023-09-05 20:27:06 +00:00
Rafael Mendonça França 5bd10ff533
Merge pull request #49118 from akhilgkrishnan/generate-token-for-release-note
[skip ci] Description added for `ActiveRecord::Base.generates_token_for` method in 7.1 release note
2023-09-05 15:21:38 -04:00
Rafael Mendonça França 43617c4cea
Merge pull request #49157 from adrianna-chang-shopify/ac-contrib-docs-addition
[ci skip] Instruct contributors to use 'ci skip' when submitting docs
2023-09-05 15:07:07 -04:00
Adrianna Chang 5f5533e96c
Instruct contributors to use 'ci skip' when submitting doc changes 2023-09-05 14:05:29 -04:00
Alex Baldwin cebac599b8 Document clean chain behavior for ActiveRecord scope 2023-09-05 12:37:13 -04:00
Eileen M. Uchitelle e32f0b8bb2
Merge pull request #49114 from gmcgibbon/cpk_id_guides
Add composite primary key examples to Rails guides
2023-09-05 11:37:22 -04:00
Gannon McGibbon 847bd59268 [skip ci] Add composite primary key examples to Rails guides
- Action Controller Overview: Add example of how a cpk record can be
  found using a show action.
- Action View Form Helpers: Add example of what a form updating a cpk
  record looks like.
- Action View Helpers: Add examples for url_for and link_to cpk record
  urls.
2023-09-05 10:33:27 -05:00
Noah Gibbs 351f05579f
Active Record query guide: add a composite primary key example for find 2023-09-05 15:54:14 +01:00
Adrianna Chang 6633671e3a
Merge pull request #49150 from Shopify/rails_guides_updates_for_composite_primary_keys
Rails Guides: describe composite primary keys (CPK) for migrations and querying
2023-09-05 09:06:23 -04:00
Noah Gibbs 586c79d8b0
Mention composite primary keys for migrations and querying 2023-09-05 12:34:40 +01:00
Ryuta Kamizono 5fc58c86d2
Merge pull request #49148 from deepakmahakale/release_notes_7_1/minor_code_block_changes
[skip ci] Minor formatting fixes for code blocks
2023-09-05 19:54:04 +09:00
Deepak Mahakale ba7def2e53 [skip ci] rewhere argument on #merge deprecated 2023-09-05 16:09:05 +05:30
Deepak Mahakale a16f1907ff [skip ci] Minor formatting fixes for code blocks 2023-09-05 15:40:56 +05:30
Petrik de Heus 42db7f307f
Merge pull request #49126 from tnir/tn-guide-remove-classic-from-engines
Simplify explanation by removing docs for classic mode
2023-09-04 10:31:08 +02:00
Vipul A M f324203923
Merge pull request #49125 from akhilgkrishnan/remove-webpacker-reference
[skip ci] Remove webpacker guide reference
2023-09-04 12:51:34 +05:30
Takuya Noguchi 258a908a0a Simplify explanation by removing docs for classic mode
Signed-off-by: Takuya Noguchi <takninnovationresearch@gmail.com>
2023-09-04 06:29:33 +00:00
Akhil G Krishnan 4631788d0f [skip ci] Remove webpacker guide reference 2023-09-04 09:37:03 +05:30
Akhil G Krishnan 7d80ccb8ce [skip ci] Description added for ActiveRecord::Base.generates_token_for method in 7.1 release note
[skip ci] Added PR reference

[skip ci] review changes updated

[skip ci] review changes updated
2023-09-03 23:26:29 +05:30
Akhil G Krishnan 04e0b4bfc2 [skip ci] Description added for Active Record API for general async queries in 7.1 release note 2023-09-02 14:51:14 +05:30
Sean Doyle e85a3ec624
Change `has_secure_token` default to `on: :initialize`
Follow-up to [#47420][]

With the changes made in [#47420][], `has_secure_token` declarations can
be configured to execute in an `after_initialize` callback. This commit
proposed a new Rails 7.1 default: generate all `has_secure_token` values
when their corresponding models are initialized.

To preserve pre-7.1 behavior, applications can set
`config.active_record.generate_secure_token_on = :create`.

By default, generate the value when the model is initialized:

```ruby
class User < ApplicationRecord
  has_secure_token
end

record = User.new
record.token # => "fwZcXX6SkJBJRogzMdciS7wf"
```

With `config.active_record.generate_secure_token_on = :create`, generate
the value when the model is created:

```ruby
 # config/application.rb
config.active_record.generate_secure_token_on = :create

 # app/models/user.rb
class User < ApplicationRecord
  has_secure_token on: :create
end

record = User.new
record.token # => nil
record.save!
record.token # => "fwZcXX6SkJBJRogzMdciS7wf"
```

[#47420]: https://github.com/rails/rails/pull/47420

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2023-09-01 20:17:22 +00:00
Jean Boussier 9fd3d03dab
Merge pull request #49105 from Earlopain/ar-normalizes-where
Document `where` support for AR `normalizes`
2023-09-01 19:02:14 +02:00
Adrianna Chang d3981d1840
Merge pull request #49103 from akhilgkrishnan/activemodel-notable-release-note
[skip ci] ActiveModel notable changes added to 7.1 release note
2023-09-01 12:50:10 -04:00
Akhil G Krishnan 369be4a723 [skip ci] ActiveModel notable changes added to 7.1 release note
[skip ci] review changes updated
2023-09-01 22:14:53 +05:30
Earlopain 830957e213
Document `where` support for AR `normalizes`
Also some other small changelog tweak:
* Add normalize_value_for to the activerecord changelog
* Fix a wrong method reference in the 7.1 release notes
2023-09-01 18:13:23 +02:00
Akhil G Krishnan cd5c61a77b [skip ci] Description added for Allow templates to set strict locals in 7.1 release note 2023-09-01 20:12:47 +05:30
Rafael Mendonça França 96cc933044
Merge pull request #49097 from akhilgkrishnan/missing-markdown
[skip ci] Added the missing code block highlights in guides
2023-08-31 15:22:41 -04:00
Rafael Mendonça França 8b3dc1a06e
Merge pull request #49092 from akhilgkrishnan/trilogy-release-note
[skip ci] Trilogy description added for rails 7.1 release note
2023-08-31 15:15:33 -04:00
Rafael Mendonça França 9e461a3f15
Merge pull request #49094 from akhilgkrishnan/activejob-notable-release-note
[skip ci] ActionJob notable changes added to 7.1 release note
2023-08-31 15:03:37 -04:00
Akhil G Krishnan e556a4a0e6 Added the missing codeblock highlights in guides
Rubocop fix
2023-08-31 21:51:04 +05:30
Akhil G Krishnan 62db35de39 [skip ci] ActionJob notable changes added to 7.1 release note 2023-08-31 11:32:23 +05:30
Akhil G Krishnan a4e24b95f4 [skip ci] ActionView notable changes added to 7.1 release note 2023-08-31 10:50:30 +05:30
Akhil G Krishnan d78e664a8f [skip ci] Trilogy description added for rails 7.1 release note 2023-08-31 10:28:02 +05:30
Ryuta Kamizono c62a361d45
Merge pull request #49078 from ilyaabramovich/patch-1
Fix generated SQL in code example using .unscoped with block

[ci-skip]
2023-08-31 12:42:56 +09:00
Rafael Mendonça França fccdc02cba
Merge pull request #49085 from akhilgkrishnan/actionmailbox-notable-release-note
[skip ci] ActionMailbox notable changes  added to 7.1 release note
2023-08-30 13:54:49 -04:00
Rafael Mendonça França a408077fe1
Merge pull request #49086 from akhilgkrishnan/activerecord-release-notes
[skip ci] ActiveRecord notable changes, deprecations and removals  added to 7.1 release note
2023-08-30 13:52:20 -04:00
Akhil G Krishnan b52c9e04dc Rails.application.deprecators description added for rails 7.1 release note
minor fix

Request changes updated

review changes updated
2023-08-30 20:00:12 +05:30
Akhil G Krishnan 5e7b1c40ea [skip ci] ActionMailbox notable changes added to 7.1 release note
[skip ci] ActionMailbox notable changes  added to 7.1 release note
2023-08-30 18:40:04 +05:30
Akhil G Krishnan 6f40b35dd5 [skip ci] ActiveRecord deprecations and removals added to 7.1 release note 2023-08-30 18:37:01 +05:30
Ilya Abramovich ef1b07b291
Fix generated SQL in code example using .unscoped with block
Fixes generated SQL for code sample of using `.unscoped` method with block as it was invalid
2023-08-29 18:24:00 +03:00
Adrianna Chang 9d8ac620af
Merge pull request #49059 from deepakmahakale/release_notes_7_1/activerecord_normalizes
[skip ci] Add ActiveRecord::Base.normalizes to 7.1 release notes
2023-08-29 11:05:50 -04:00
Adrianna Chang 684a2a278f
Merge pull request #49074 from akhilgkrishnan/activestorage-notable-release-note
[skip ci] ActiveStorage notable changes added to 7.1 release note
2023-08-29 11:02:07 -04:00
Adrianna Chang 5ff6a97381
Merge pull request #49076 from akhilgkrishnan/actionpack-notable-release-note
[skip ci] Railties, ActionPack notable changes and deprecations added to 7.1 release note
2023-08-29 11:01:20 -04:00
Deepak Mahakale 53a44b98b6 [skip ci] Add ActiveRecord::Base.normalizes to 7.1 release notes
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
2023-08-29 20:31:14 +05:30
Akhil G Krishnan 19cb350296 [skip ci] ActiveStorage notable changes added to 7.1 release note
Request changes updated
2023-08-29 20:27:35 +05:30
Akhil G Krishnan c0ee485db8 [skip ci] ActionPack notable changes and deprecations added to 7.1 release note
Request changes updated
2023-08-29 20:24:13 +05:30
Adrianna Chang 72b356cdf5
Merge pull request #49061 from deepakmahakale/release_notes_7_1/removals_for_actionmailer
[skip ci] Add deprecations/removals for action-mailer, active-storage and active-job
2023-08-29 10:08:53 -04:00
Akhil G Krishnan 6b507f87e3 method description added in 7.1 release note
Review changes updated
2023-08-29 12:22:03 +05:30
Deepak Mahakale 8c4e216ab0 [skip ci] Add deprecations/removals for action-mailer, active-storage and active-job to 7.1 release notes 2023-08-29 10:17:13 +05:30
Rafael Mendonça França a2a520e733
Merge pull request #49057 from akhilgkrishnan/action_cable_release_note
[skip ci] ActionCable notable changes added to 7.1 release note
2023-08-28 12:55:30 -04:00
Rafael Mendonça França 0b1f33e684
Merge pull request #49035 from akhilgkrishnan/action_mailer_release_note
[skip ci] Added ActionMailer notable features and deprecations to 7.1 release note
2023-08-28 12:53:10 -04:00
Rafael Mendonça França fcda3a8857
Merge pull request #49034 from akhilgkrishnan/perform_all_later_to_relase_note_7_1
[skip ci] Add description for perform_all_later method in 7.1 release note
2023-08-28 12:47:49 -04:00
Akhil G Krishnan 3228f6421f [skip ci] ActionCable notable changes added to 7.1 release note 2023-08-28 12:24:35 +05:30
Dave Aronson f6b987d521
Replace repeated list literals in Getting Started guide w/ a constant (#49007)
* Replace list literals w/ Visible::VALID_STATUSES

In Getting Started guide, in the article and comment status dropdowns, use Visible::VALID_STATUSES instead of repeating the list of valid statuses.  This makes the code DRYer and more expressive.  This PR also adds a comment to that effect.

* Remove text changes, leave just code

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2023-08-25 17:14:08 -04:00
Akhil G Krishnan c95796489a Added ActionMailer notable features and deprecations to 7.1 release note
Unwanted changes
2023-08-25 17:56:09 +05:30
Akhil G Krishnan 26931def8c Add description for perform_all_later method in 7.1 release note 2023-08-25 16:43:00 +05:30
Dave Aronson 4ac237de74
select existing article status if any, in Getting Started Guide -- Fixes #45028 (mostly) (#49010)
* select existing article status if any

In the Getting Started guide, in the dropdown for an article or comment's status, pre-selecting `public` will make _all_ articles seem `public` even if their status is really something else -- even `nil`.  This was reported in issue #45028.  Selecting `article.status || 'public'` instead will fix this, in _most_ cases.  Pre-existing articles with `nil` status will show up as `public`, but if the form is submitted, they will indeed become `public`.

This commit makes that change, and adds text to explain why it is done.

* Simplify wording of changes to Getting Started

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2023-08-24 17:31:46 -04:00
Rafael Mendonça França 90bdbe0645
Merge pull request #49026 from akhilgkrishnan/release_note_docker
Add default docker files description to 7.1 release note [skip ci]
2023-08-24 14:54:10 -04:00
Akhil G Krishnan 3146a1c360 Add default docker files description to 7.1 release note
Added the review changes

review changes updated
2023-08-24 21:46:44 +05:30
Rafael Mendonça França 1c3aed0442
Merge pull request #49022 from akhilgkrishnan/release_7_1_railties
[skip ci] Added changes of railties to release notes for 7.1
2023-08-24 12:12:44 -04:00
Akhil G Krishnan 25e0fabe53 Added changes of railties to release notes for 7.1
review changes updated
2023-08-24 21:33:46 +05:30
Rafael Mendonça França 57b79cf162
Improve guide for Customizing form builder
Make the example complete so people can follow along insted of having
to understand the implicit context that you need an existing helper
called `text_field_with_label` to make the example work.

Fixes #49027.
2023-08-24 15:32:01 +00:00
Akhil G Krishnan 0f7f9e3d5e [skip ci] Moved sh to bash and added missing $ 2023-08-24 18:48:20 +05:30
Sean Doyle 90c901137f Document `response.parsed_body` in 7.1 release notes
Add notes for [#47144][] to the 7.1 Release Notes.

Additionally, in the time since that was merged, both Nokogiri and
Minitest have merged the PRs mentioned to integrate support for Ruby's
Pattern matching (https://github.com/sparklemotion/nokogiri/pull/2523
and https://github.com/minitest/minitest/pull/936, respectively).

This commit adds coverage for those new assertions, and incorporates
guidance into the release notes.

[#47144]: https://github.com/rails/rails/pull/47144
2023-08-23 15:33:52 -04:00
Akhil G Krishnan d104005053 [skip ci] Added missing $ for a bash script 2023-08-23 15:58:08 +05:30
Shouichi Kamiya b8decf79d8 Add an option to start rails console in sandbox mode by default
To avoid accidental writing to the production database, I always start
rails console in sandbox mode. I only start rails console in non-sandbox
mode when I'm sure I want to write to the production database.

`sandbox_by_default` option is added to start rails console in sandbox
mode by default. With this option turned on, `--no-sandbox` must be
specified to start rails in non-sandbox mode.

Note that this option is ignored when rails environment is development
or test.
2023-08-22 09:23:52 +09:00
Petrik a0cc3e9a07 Add strict loals and Rails.application.deprecators to 7.1 release notes
[ci-skip]
2023-08-21 22:34:51 +02:00
Rafael Mendonça França 7797681cb2
Simplify the logic in the documentation. 2023-08-21 19:10:13 +00:00
Rafael Mendonça França 461ee94a0f
Merge pull request #44981 from tan-linx/improvement/how-to-use-remote-selenium-configuration
Add additional config to docs about how to use remote browser in test
2023-08-21 15:08:46 -04:00
Rafael Mendonça França 3b08b674db
Remove Brakeman from security guide
We should not be endorsing any external library in our guides.
2023-08-21 17:48:31 +00:00
Rafael Mendonça França 0306f5ad40
Add more async queries support to release notes
[ci skip]
2023-08-21 16:29:14 +00:00
Rafael Mendonça França c6dd10a9de
Create draft of 7.1 release notes 2023-08-21 16:24:25 +00:00
Vipul A M 5e2d79b5cc
Wordsmitthing and replaced all NBSP's with a single space for Assets Pipeline guide (#48980)
* Wordsmitthing and replaced all NBSP's with a single space

* Remove reference of webpacker guide from asset pipeline guide
2023-08-19 21:48:06 +05:30
Sander Verdonschot 315db730cc
Update job testing guidelines
The current example test for jobs using `perform_now` to run the job inline. This is problematic for jobs that have retries configured, as any exception that is retried will be silently rescued. Ideally, the test will still fail because the job did not perform the work it was supposed to, but it makes finding the root cause a lot harder.

Testing with `perform_enqueued_jobs` and `perform_later` gets around this problem, as the retries are also performed immediately and, assuming that the exception happens consistently, it will bubble up after exhausting its retries.

Therefore, this PR updates the basic test guidance to suggest `perform_enqueued_jobs` and `perform_later` over `perform_now`.

Both described behaviours make it harder to test that a job raises a specific exception, so this requires special handling, which I added a paragraph on. I can pull that out to a separate PR if desired.
2023-08-16 16:49:46 -04:00
Akhil G Krishnan 8ae0b4ac7a [skip ci] Testing by line range documentation added in guide
Review changes updated

Update railties/lib/rails/commands/test/USAGE

Co-authored-by: Yasuo Honda <yasuo.honda@gmail.com>

Update guides/source/testing.md

Co-authored-by: Yasuo Honda <yasuo.honda@gmail.com>
2023-08-15 07:40:17 +05:30
Josephine 03f5f45615
Reference correct method from 'deliver_now' example code 2023-08-11 07:11:16 -07:00
r7kamura 7f52979f0a Remove unnecessary isolation_level setting from load_defaults 7.0
The default value of `ActiveSupport::IsolatedExecutionState.isolation_level` is set to `:thread`, regardless of whether `load_defaults 7.0` is used or not.

- https://github.com/rails/rails/blob/v7.0.4/activesupport/lib/active_support/isolated_execution_state.rb

If so, there is no need to set this in `load_defaults 7.0`. This Pull Request has been created to remove this unnecessary setting
2023-08-09 14:39:38 +09:00
Akhil G Krishnan a46f4c28c1 Removes Webpacker from the guides index page
webpacker file removed
2023-08-08 23:02:36 +05:30
Sean Doyle b1db663a12 Active Storage Guides: change `fixture_file_upload` to `file_fixture_upload`
Follow-up to [#48857][]

Mention the recently introduced `file_fixture_upload` alias in the
Active Storage Overview guides to reinforce the symmetry with the
`file_fixture` test helper method.

[#48857]: https://github.com/rails/rails/pull/48857

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-08-06 13:10:40 -05:00
Rafael Mendonça França 73cb71b9af
Link to the API and let the documentation generator point to edge 2023-08-04 16:54:56 -04:00
Sean Doyle 6cafc49d2c Rename `fixture_file_upload` method to `file_fixture_upload`
The naming difference between the test harness' [file_fixture][] helper
made available through Active Support (along with the
`file_fixture_path` configuration value) and the integration test
harness' [fixture_file_upload][] is a constant source of confusion and
surprise.

Since Active Support is more ubiquitous, this commit renames the
`fixture_file_upload` method to `file_fixture_upload` to match the order
of words in `file_fixture` and `file_fixture_path`.

To preserve backwards compatibility, declare a `fixture_file_upload`
alias to be preserved into the future (or removed at a future point in
time).

[file_fixture]: https://edgeapi.rubyonrails.org/classes/ActiveSupport/Testing/FileFixtures.html#method-i-file_fixture
[fixture_file_upload]: https://edgeapi.rubyonrails.org/classes/ActionDispatch/TestProcess/FixtureFile.html#method-i-fixture_file_upload
2023-08-04 12:40:17 -04:00
Jack CP aaf844af73 Fix typo in ActiveRecord Query guide
The SQL generated by this query (at 13.1.3.2):

```ruby
Author.joins(books: [{ reviews: { customer: :orders } }, :supplier] )
```

Is said to generate SQL whose select list is comprised of `*`, not
`authors.*`
2023-08-04 17:20:02 +12:00
Mike Dalessio bfeb580264
Introduce config.dom_testing_default_html_version
which controls the HTML parser used by rails-dom-testing assertions.

The config parameter is set to :html5 in Rails 7.1 if the Nokogiri
HTML5 parser is supported.
2023-08-03 11:16:52 -04:00
Akhil G Krishnan c0b850ab92 [skip ci] Added missing parathesis in guide 2023-08-03 19:30:25 +05:30
Rafael Mendonça França e980f158a4
Merge pull request #48847 from seanpdoyle/omit-webdrivers-from-gemfile-template
Omit `webdrivers` gem from `Gemfile` template
2023-08-02 13:49:28 -04:00
Rafael Mendonça França 3f500d7937
Merge pull request #48806 from akhilgkrishnan/punctuation-and-grammer-fix
[skip ci] Added some grammatical changes and missing punctuations
2023-08-01 18:07:34 -04:00
Akhil G Krishnan 73e6ddc273 [skip ci] Added some grammatical changes and puntuations
fixed the line length

Alignment fix

Alignment fix

Update guides/source/active_record_multiple_databases.md

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>

Update guides/source/active_record_multiple_databases.md

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>

Update guides/source/active_record_multiple_databases.md

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>

Update guides/source/active_record_multiple_databases.md

Co-authored-by: Alex Ghiculescu <alex@tanda.co>

updated essential with important
2023-08-01 23:32:07 +05:30
Akhil G Krishnan f171101f17 Fixed few typos in tests and guide
reverted the unwanted change

fixed the alignment

review changes updated
2023-08-01 23:31:17 +05:30
Sean Doyle 9a53234695 Omit `webdrivers` gem from `Gemfile` template
As of Selenium 4.6, [the Selenium Manager is capable of managing Chrome
Driver installations and integrations][readme]. As of Selenium 4.11, the
Selenium Manager is capable of [capable of resolving the Chrome for
Testing installation][] path.

By omitting the `gem` declaration from the `Gemfile.tt`, newly generated
applications and applications updating their `Gemfile` in lockstep with
newer Rails versions can shed the dependency and avoid test failures
introduced by newly released Chrome versions (like, for example,
[titusfortner/webdrivers#247][]).

[readme]: 43f8ac436c (update-selenium-manager)
[titusfortner/webdrivers#247]: https://github.com/titusfortner/webdrivers/issues/247
[capable of resolving the Chrome for Testing installation]: https://github.com/rails/rails/pull/48847#issuecomment-1656756862

Co-authored-by: Titus Fortner <titusfortner@users.noreply.github.com>
2023-08-01 09:22:08 -04:00
soartec-lab c8985995a7 Update `listen` gem version in guide [skip ci] 2023-07-29 16:15:56 +09:00
Jonathan Hefner 36f9cfdd90 Lazily deserialize cache entries
This adds a cache optimization such that expired and version-mismatched
cache entries can be detected without deserializing their values.  This
optimization is enabled when using cache format version >= 7.1 or a
custom serializer.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2023-07-27 14:58:35 -05:00
Jonathan Hefner 3efb84486e Support replacing cache compressor
This commit adds support for replacing the compressor used for
serialized cache entries.  Custom compressors must respond to `deflate`
and `inflate`.  For example:

  ```ruby
  module MyCompressor
    def self.deflate(string)
      # compression logic...
    end

    def self.inflate(compressed)
      # decompression logic...
    end
  end

  config.cache_store = :redis_cache_store, { compressor: MyCompressor }
  ```

As part of this work, cache stores now also support a `:serializer`
option.  Similar to the `:coder` option, serializers must respond to
`dump` and `load`. However, serializers are only responsible for
serializing a cached value, whereas coders are responsible for
serializing the entire `ActiveSupport::Cache::Entry` instance.
Additionally, the output from serializers can be automatically
compressed, whereas coders are responsible for their own compression.

Specifying a serializer instead of a coder also enables performance
optimizations, including the bare string optimization introduced by cache
format version 7.1.
2023-07-26 11:59:09 -05:00
Akhil G Krishnan f4233f5bd0 [ci skip] Add --skip-dev-gems rails command line argument to the guide 2023-07-24 12:57:01 +05:30
Santiago Bartesaghi 76da537a39 [ci skip] ActiveStorage guides don't recommend using a deprecated config 2023-07-21 16:11:23 -03:00
Dave Powers f7c5e7e75c
Improve readability of case sensitivity description 2023-07-20 16:30:16 -04:00
Adrianna Chang 0ccde297a1
Merge pull request #48752 from wildmaples/patch-1
Use different bucket name in AS Guide for clarity
2023-07-20 12:06:42 -04:00
Maple Ong 3fd850fe0b [ci skip] Use different bucket name for clarity
Currently the service specified here is `:s3` and it could be confused for the `Service::S3Service`. The modified code example shows more clarity to the reader that the service in this case here refers to the bucket name outlined in `storage.yml` rather than the adapter service.
2023-07-20 09:38:37 -04:00
Shunichi Ikegami ea8795040e Fix ActiveStorage Overview CORS examples.
S3 CORS configuration's `ExposeHeaders` corresponds to Access-Control-Expose-Headers that indicates which **response** headers should be made available to scripts running in the browser.
But current example contains **request** headers (e.g. Content-MD5).
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers

`AllowedHeaders` corresponds to Access-Control-Allow-Headers that indicates which **request** headers is allowed.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers

Additionally, `Origin` is not required in Access-Control-Allow-Headers.
User agents automatically add the Origin request header to CORS request and JS can't control it's behavior.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin
2023-07-19 19:00:37 +09:00
Yasuo Honda 93453aaf23
Merge pull request #48728 from ghiculescu/patch-11
Improve AR Encryption docs
2023-07-18 22:49:59 +09:00
Ron Shinall aba723bffb Fix documentation error for Delegated Types 2023-07-13 13:34:15 -06:00
Dan Arnfield 95b2add89e Document common ActiveStorage issues
* How to keep existing attachments on a has_many_attached when uploading new ones
* How to retain uploaded files when a form submission fails validation
[ci skip]
2023-07-13 09:19:27 -05:00
Alex Ghiculescu cdebf39e6c
Improve AR Encryption docs 2023-07-13 16:30:22 +10:00
Jean Boussier 7b52f569c1
Merge pull request #48600 from Shopify/transaction-commit-on-return
Active Record commit transaction on `return`, `break` and `throw`
2023-07-10 10:55:41 +02:00
Jean Boussier 5fbaa524b9 Active Record commit transaction on `return`, `break` and `throw`
Fix: https://github.com/rails/rails/issues/45017
Ref: https://github.com/rails/rails/pull/29333
Ref: https://github.com/ruby/timeout/pull/30

Historically only raised errors would trigger a rollback, but in Ruby `2.3`, the `timeout` library
started using `throw` to interupt execution which had the adverse effect of committing open transactions.

To solve this, in Active Record 6.1 the behavior was changed to instead rollback the transaction as it was safer
than to potentially commit an incomplete transaction.

Using `return`, `break` or `throw` inside a `transaction` block was essentially deprecated from Rails 6.1 onwards.

However with the release of `timeout 0.4.0`, `Timeout.timeout` now raises an error again, and Active Record is able
to return to its original, less surprising, behavior.
2023-07-10 10:37:42 +02:00
Lewis Buckley 08a79ce284
Add a load hook for `ActiveModel::Model`
ActiveRecord::Base has a dedicated ActiveSupport load hook. This adds an
additional hook for ActiveModel::Model, so that when ActiveModel is
being used without ActiveRecord, it can still be modified.
2023-07-09 13:08:34 +01:00
Mike Dalessio 44d3b44d9d
Add config.action_text.sanitizer_vendor
Rails 7.1 defaults to Rails::HTML::Sanitizer.best_supported_vendor,
earlier configs will use Rails::HTML4::Sanitizer.

Related to #48523 / 55bca6b8.
2023-07-04 08:54:46 -04:00
zzak a234669d63
Disable database prepared statements when query logs are enabled
Fixes #48398

Prepared Statements and Query Logs are incompatible features due to query logs making every query unique.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2023-07-03 16:59:44 +09:00
Xavier Noria 0568bc9a90 Introduce config.autoload_lib_once(ignore:) 2023-06-29 09:15:17 +02:00
Xavier Noria 90047b52cd Document and test lib & config.add_autoload_paths_to_load_path 2023-06-27 23:50:43 +02:00
Guillermo Iguaran 10b4bd597f
Merge branch 'main' into hm-config-exception-level 2023-06-26 19:07:08 -07:00
Matthew Hirst 00ebbbd746
This allows Rails projects with multiple databases to specify which database they would like the migrations to be copied to. 2023-06-26 19:27:47 +02:00
Hartley McGuire 519577ecc3
Make the log level in DebugExceptions configurable
This middleware has been logging at a FATAL level since the first
[commit][1] in Rails (the code originally lived in
actionpack/lib/action_controller/rescue.rb). However, FATAL is
documented in the Ruby Logger [docs][2] as being for "An unhandleable
error that results in a program crash.", which does not really apply to
this case since DebugExceptions is handling the error. A more
appropriate level would be ERROR, which the Ruby Logger docs describe as
"A handleable error condition."

This commit introduces a new configuration for the DebugExceptions log
level so that new apps will have it set to ERROR by default and ERROR
can eventually be made the default.

[1]: db045dbbf6
[2]: https://ruby-doc.org/3.2.1/stdlibs/logger/Logger/Severity.html
2023-06-25 23:11:39 -04:00
Xavier Noria f27dd78b07 Remove unnecessary Rails module usage 2023-06-25 10:52:53 +02:00
Xavier Noria a35689a533
Merge pull request #48572 from rails/autoload-lib
Introduce config.autoload_lib
2023-06-25 10:43:10 +02:00
Xavier Noria e1321a291f Introduce config.autoload_lib 2023-06-25 10:17:08 +02:00
Jorge Manrubia c8d26bb647
Add a encryption option to support previous data encrypted non-deterministically with a SHA1 hash digest (#48530)
* Make sure active record encryption configuration happens after initializers have run

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>

* Add a new option to support previous data encrypted non-deterministically with a hash digest of SHA1

There is currently a problem with Active Record encryption for users updating from 7.0 to 7.1 Before
#44873, data encrypted with non-deterministic encryption was always using SHA-1. The reason is that
`ActiveSupport::KeyGenerator.hash_digest_class` is set in an after_initialize block in the railtie config,
but encryption config was running before that, so it was effectively using the previous default SHA1. That
means that existing users are using SHA256 for non deterministic encryption, and SHA1 for deterministic
encryption.

This adds a new option `use_sha1_digest_for_non_deterministic_data` that
users can enable to support for SHA1 and SHA256 when decrypting existing data.

* Set a default value of true for `support_sha1_for_non_deterministic_encryption` and proper initializer values.

We want to enable the flag existing versions (< 7.1), and we want it to be false moving by
default moving forward.

* Make sure the system to auto-filter params supports different initialization orders

This reworks the system to auto-filter params so that it works when encrypted
attributes are declared before the encryption configuration logic runs.

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>

---------

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>
2023-06-25 10:16:22 +02:00
Christian Schmidt 11ed5b5c52 Rename Range#overlaps? to Range#overlap?
Rename for consistency with #include? and #cover?
2023-06-23 10:25:59 +02:00
Alex Baldwin e4002fcc40 Document Dev Container CLI setup in guides 2023-06-21 15:53:27 -04:00
zzak 8725f61cdb
Merge pull request #48526 from ghiculescu/active-job-docs
Update Active Job testing guide
2023-06-21 14:38:31 +09:00
Alex 10bb51a123 Update Active Job testing guide
The testing guide for Active Job currently implies that when you queue a job it will be performed.

This isn't true; by default jobs are enqueued, not performed.

This PR fleshes out the docs a bit to show both examples, and adds a test to confirm the default behaviour.
2023-06-20 09:58:33 +10:00
Mike Dalessio cbc79095c2
Update guides generation to use Nokogiri's HTML5 parser
Note that the most frequent change to the output are:

- attribute values, most often data-clipboard-text. libgumbo
  entity-escapes fewer characters in attribute values than libxml2, and
  wraps them in double-quotes. In particulary `>` and `<` are not
  escaped per the HTML5 spec.
- linebreaks are different for some HTML elements, particularly lists.
2023-06-19 15:38:13 -04:00
Petrik de Heus 676fdb1414
Merge pull request #48404 from soartec-lab/task/add-doc-to-activerecord-pick
Added documentation for `ActiveRecord::Relation#pick` [skip ci]
2023-06-19 15:57:03 +02:00
soartec-lab 48a26f5073 Added documentation for `ActiveRecord::Relation#pick` [skip ci]
- Add nuances of the primarily useful cases to the code examples
- Changed description to use some wording from API docs
2023-06-19 17:39:07 +09:00
Petrik 275a6130c1 Set secret_key_base on config in bug_report_templates
`secrets` are deprecated. For the bug templates we can set the
`secret_key_base` on `config` instead.
2023-06-18 18:58:22 +02:00
sampatbadhe 79932d109d Update note for add_enum_value - Enum values can be renamed 2023-06-16 05:29:15 +05:30
Ray Faddis ce6047f84f Adding PG enum rename, add value, and rename value migration helpers 2023-06-15 10:03:23 -04:00
Guillermo Iguaran 01363bd7e7
Merge pull request #48467 from swanson/matt/rendering-docs-update
Add notes about renderable option to guide
2023-06-14 00:53:38 -07:00
matt swanson a9f1558be5
Typo 2023-06-14 00:05:36 -04:00
matt swanson bcd5dd6c8d
Add notes about renderable option to guide 2023-06-13 23:53:42 -04:00
soartec-lab d1a1f541e5 Changed `ActiveRecord::Relation#pluck` guide to be more similar to the API docs for better clarity [skip ci] 2023-06-14 11:28:36 +09:00
Jonathan Hefner bd15567fe9 Use cache :coder option to specify :message_pack
In #48104, `:message_pack` was added as a supported value for the cache
format version because the format version essentially specifies the
default coder.  However, as an API, the format version could potentially
be used to affect other aspects of serialization, such as the default
compression format.

This commit removes `:message_pack` as a supported value for the format
version, and, as a replacement, adds support for specifying
`coder: :message_pack`:

  ```ruby
  # BEFORE
  config.active_support.cache_format_version = :message_pack

  # AFTER
  config.cache_store = :redis_cache_store, { coder: :message_pack }
  ```
2023-06-11 15:30:10 -05:00
zzak 11213ce8eb
Add note about running tests at a specific line 2023-06-11 08:38:21 +09:00
Genesis Bustamante Lillo 5251fcfb36
Correct directory-checking block in security.md
This Pull Request corrects one line in a code block.

In section _File Downloads_, the block that presents a solution against malicious file downloads expects that the path to a folder named 'file' (variable `basename`) matches the path to a folder which is 3 levels above, or else, it will raise an exception:

```ruby
raise if basename != File.expand_path(File.join(File.dirname(filename), '../../../'))
```

and that is impossible. It should instead be:

```ruby
raise if basename != File.expand_path(File.dirname(filename))
```

This bug goes as far back as v2.3 of the guide. I did not look further.
2023-06-01 21:57:18 -04:00
Guillermo Iguaran 64ab34c622
Merge pull request #48367 from ally1002/guide-back-to-top
Fixing fetch image on 'back-to-top' button
2023-06-01 12:51:00 -07:00
Alysson Rosa 937b307e84 Fixing fetch image on 'back-to-top' button 2023-06-01 09:53:39 -03:00
Guillermo Iguaran d026af43c3
Merge pull request #48354 from ally1002/guide-back-to-top
Adding the button using JS and styling with CSS and Image [ #48277 ]
2023-06-01 00:38:41 -07:00
Alysson Rosa 22397bec6f Adding the button using JS and styling with CSS and Image 2023-05-31 17:38:44 -03:00
Eileen M. Uchitelle ced5e77936
Merge pull request #48353 from eileencodes/set-default-shard-from-connects_to-hash
Set default_shard from connects_to hash
2023-05-31 15:29:57 -04:00
eileencodes 0d41bfd3cc
Set default_shard from connects_to hash
If an application is using sharding, they may not want to use `default`
as the `default_shard`. Unfortunately Rails expects there to be a shard
named `default` for certain actions internally. This leads to some
errors on boot and the application is left manually setting
`default_shard=` in their model or updating their shards in
`connects_to` to name `shard_one` to `default`. Neither are a great
solution, especially if Rails can do this for you. Changes to Active
Record are:

* Simplify `connects_to` by merging `database` into `shards` kwarg so we
can do a single loop through provided options.
* Set the `self.default_shard` to the first keys in the shards kwarg.
* Add a test for this behavior
* Update existing test that wasn't testing this to use `default`. I
could have left this test but it really messes with connections in the
other tests and since this isn't testing shard behavior specifically, I
updated it to use `default` as the default shard name.

This is a slight change in behavior from existing applications but
arguably this is fixing a bug because without this an application won't
boot. I originally thought that this would require a huge refactoring to
fix but realized that it makes a lot of sense to take the first shard as
they default. They should all have the same schema so we can assume it's
fine to take the first one.

Fixes: #45390
2023-05-31 12:52:12 -04:00
Rafael Mendonça França 54de0cb2ee
Merge pull request #48293 from flavorjones/flavorjones-support-html5-sanitizer
Update Action View to use HTML5 standards-compliant sanitizers
2023-05-30 16:00:13 -04:00
Matt Almeida b02bfa14bf
Link console1984 where mentioned in ARE guide 2023-05-29 14:02:31 -04:00
Mike Dalessio ce43ac6088
Add support for HTML5 sanitizers
* new config value: action_view.sanitizer_vendor
* SanitizerHelper defaults to Rails::HTML4::Sanitizer
* 7.1 config defaults to Rails::HTML5::Sanitizer if it's supported
2023-05-28 14:00:35 -04:00
zzak 073269c9b9
Merge pull request #48288 from zzak/rdoc-fixed-width-namespaces
Use short-form fixed-width RDoc form for namespaces
2023-05-25 07:14:47 +09:00
zzak e579afb16d
Update guidelines on fixed-width font for constants 2023-05-25 06:51:59 +09:00
Rafael Mendonça França 61accb7dea
Merge pull request #45867 from jdufresne/show-rescuable-exceptions
Make the test environment show rescuable exceptions in responses
2023-05-24 13:45:45 -04:00
cjilbert504 f7623a0af4
Update documentation to include proper class name formatting and pronoun problem fix 2023-05-23 14:40:31 -05:00
zzak 175fab9bb6
Link to ActionView::Helpers top level namespace for all helpers
Co-authored-by: Mike Munroe <mike@oblsk.com>
2023-05-22 18:57:53 +09:00
Jonathan Hefner 83e69c22e9 Run after_bundle blocks with app:template command
App templates may contain `after_bundle` blocks which should be run
after the template is executed, after running `bundle install`.  For
example:

  ```ruby
  gem "devise"

  after_bundle do
    generate "devise:install"
  end
  ```

Prior to this commit, `bundle install` and `after_bundle` blocks were
run only when applying a template via `rails new`.  This commit makes
`bin/rails app:template` run them as well.

Co-authored-by: "Gerard (Gerry) Caulfield" <git@caulfield.me>
2023-05-21 14:34:48 -05:00
cjilbert504 e72f0db04a
Fix grammar in test line number description 2023-05-19 09:46:11 -05:00
Jonathan Hefner 43fa801967 Clean up Generators guide [ci-skip]
This rewords various parts of the Generators guide to improve clarity,
fixes punctuation, and wraps lines at ~80 characters.
2023-05-18 17:06:13 -05:00
Jonathan Hefner 221ef255e4 Rewrite Application Templates section [ci-skip]
This modifies the example application template to only use a single gem,
to run generator calls in an `after_bundle` block, and to include a
`db:migrate` call after running the generators.

This also simplifies the section's prose, and mentions
`bin/rails app:template` for running templates in existing apps.
2023-05-18 17:06:13 -05:00
Jonathan Hefner dc0dc9720e Rewrite Generators Fallbacks section [ci-skip]
This rewrites "Generators Fallbacks" section to remove the reference to
the Shoulda gem and provide a more explicit example.  This also converts
the section into a subsection of "Overriding Rails Generators", since it
is a technique to override specific generators.
2023-05-18 17:06:13 -05:00
Jonathan Hefner 9aa3b5ef56 Rewrite Overriding Generators section [ci-skip]
This replaces the "Customizing Your Workflow" section with an
"Overriding Rails Generators" section that is focused on simply
overriding a built-in generator.  Detailed information about
`config.generators` has been delegated to the Configuration guide.
Outdated information about scaffold stylesheet generation has been
removed.  Outdated information about helper test generation has been
updated.  Detailed information about hooking generators together has
been delegated to the `hook_for` API documentation.

Reverts #47712.
Closes #44490.
2023-05-18 17:06:05 -05:00
Jonathan Hefner 7f02fa990b Rewrite Overriding Templates section [ci-skip]
This changes the section to focus on overriding a scaffold view
template, since that use case is more common than overriding the helper
template.

This also moves the section further up in the guide because overriding
generator templates is easier (and more likely) than overriding
generators themselves.
2023-05-18 17:05:02 -05:00
Jonathan Hefner 384faa581f Relocate Command Line Options section [ci-skip]
Adding a command line option is a natural follow-up to creating a
generator, and the example of specifying a command line option builds on
the example from the "Creating Generators with Generators" section.
Therefore, this commit puts the "Adding Command Line Options" section
right after the "Creating Generators with Generators" section.

This commit also tweaks the section to improve clarity.
2023-05-18 17:05:02 -05:00
Jonathan Hefner 87ffba7928 Rewrite Generator Methods section to link API docs [ci-skip]
This also clarifies that `gsub_file` and `inject_into_file` (AKA
`insert_into_file`) are provided by Thor.
2023-05-18 17:05:02 -05:00
Jonathan Hefner 5d870a6a85 Link to API docs [ci-skip] 2023-05-18 17:05:02 -05:00
Jonathan Hefner 7c3bfa782e Add command output [ci-skip] 2023-05-18 17:05:02 -05:00
Jonathan Hefner 376ce48861 Use squiggly heredocs to clean up code examples [ci-skip] 2023-05-18 17:05:02 -05:00
Jonathan Hefner cc2e9ea12b Remove Rails 3 references [ci-skip]
Rails 3 is long gone. 👋
2023-05-18 17:05:02 -05:00
Jonathan Hefner e1f43ac766 Update Thor link [ci-skip] 2023-05-18 17:05:02 -05:00
zzak 254af8edc4
Merge pull request #48086 from mikepmunroe/remove-bundler-version
Clean up bundler install directions
2023-05-19 06:49:51 +09:00
zzak 49b657251c
Merge pull request #48087 from mikepmunroe/update-form-api-link
Link to Action View Form Helpers section in API
2023-05-19 06:48:41 +09:00
zzak 0d7ee466aa
Revert "Specify the maximum compatible Ruby version for Rails 5" 2023-05-18 19:46:12 +09:00
Jon Dufresne e28f147329 Make the test environment show rescuable exceptions in responses
Background
----------

During integration tests, it is desirable for the application to respond
as closely as possible to the way it would in production. This improves
confidence that the application behavior acts as it should.

In Rails tests, one major mismatch between the test and production
environments is that exceptions raised during an HTTP request (e.g.
`ActiveRecord::RecordNotFound`) are re-raised within the test rather
than rescued and then converted to a 404 response.

Setting `config.action_dispatch.show_exceptions` to `true` will make the
test environment act like production, however, when an unexpected
internal server error occurs, the test will be left with a opaque 500
response rather than presenting a useful stack trace. This makes
debugging more difficult.

This leaves the developer with choosing between higher quality
integration tests or an improved debugging experience on a failure.

I propose that we can achieve both.

Solution
--------

Change the configuration option `config.action_dispatch.show_exceptions`
from a boolean to one of 3 values: `:all`, `:rescuable`, `:none`. The
values `:all` and `:none` behaves the same as the previous `true` and
`false` respectively. What was previously `true` (now `:all`) continues
to be the default for non-test environments.

The new `:rescuable` value is the new default for the test environment.
It will show exceptions in the response only for rescuable exceptions as
defined by `ActionDispatch::ExceptionWrapper.rescue_responses`. In the
event of an unexpected internal server error, the exception that caused
the error will still be raised within the test so as to provide a useful
stack trace and a good debugging experience.
2023-05-17 06:30:28 -07:00
zzak d137b10f94
Merge pull request #47960 from chris-hewitt/patch-1
Specify the maximum compatible Ruby version for Rails 5
2023-05-16 20:44:37 +09:00
zzak b7ed4558b4
Follow #47946 and apply to release notes 2023-05-16 18:18:14 +09:00
Petrik c9b894241a Fix 'View Timings from Instrumentation' guides heading [ci-skip]
Fix the capitalization. See:
Seehttps://edgeguides.rubyonrails.org/ruby_on_rails_guides_guidelines.html#headings

Also remove an extraneous linebreak.
2023-05-15 11:01:13 +02:00
Joé Dupuis 138191a6b7 Change a confusing Action Cable guide example.
The description was mentioning broadcasting to a comment channel and
then the example broadcast to a post channel. In itself, not too
confusing, but because the example is broadcasting comments on the
post channel, it looks as if the order of parameters is reversed on
the `broadcast_to` call.
2023-05-13 20:35:02 -07:00
Noah Horton 10ce757929 Updated ActiveSupport instrumentation guide to include Server Timings info. 2023-05-13 18:17:25 +00:00
zzak cc4ccebd6e
Document bash / command-line fixed-font preferences 2023-05-13 10:36:41 +09:00
Jonathan Hefner e4fa1c4f95 Add pseudo-subsections to Instrumentation guide [ci-skip]
This organizes some related events into pseudo-subsections, such as
"Action Controller — Caching", for easier browsing.  The
pseudo-subsections are at the same content level as their parent section
so that headings and event names are rendered consistently.
2023-05-12 16:23:58 -05:00
Jonathan Hefner dc86d868d7 Document cache_prune.active_support event [ci-skip] 2023-05-12 16:14:17 -05:00
Jonathan Hefner 69d541278e Document cache_cleanup.active_support event [ci-skip] 2023-05-12 16:14:17 -05:00
Jonathan Hefner 85688a689e Document cache_{inc,dec}rement.active_support events [ci-skip] 2023-05-12 16:14:17 -05:00
Jonathan Hefner 129bdf6ac6 Document cache_delete_matched.active_support event [ci-skip] 2023-05-12 16:14:17 -05:00
Jonathan Hefner 77ed08a91f Clean up Active Support Instrumentation guide [ci-skip]
Some minor rephrasing, punctuation fixes, and helpful linking.
2023-05-12 16:14:17 -05:00
Jonathan Hefner e72eeafa9d Link to API docs [ci-skip] 2023-05-12 16:14:17 -05:00
Jonathan Hefner 22edb9d0c7 Format event names as code [ci-skip] 2023-05-12 16:14:17 -05:00
Eileen M. Uchitelle 437856ba6b
Merge pull request #48175 from eileencodes/fix-type-information-for-mysql
Clean up docs and code using mysql2 when we mean trilogy
2023-05-09 11:18:12 -04:00
Petrik de Heus 161995ba31
Merge pull request #48176 from dzunk/fix_another_ol [ci-skip]
Fix ordered list syntax in development dependencies guide
2023-05-09 17:17:14 +02:00
Matt Duszynski 5756defcda Fix ordered list syntax in development dependencies guide 2023-05-09 10:07:55 -05:00
eileencodes 74898d9b54
Clean up docs and code using mysql2
This PR does the following:

* Adds `trilogy` to lists of adapters where applicable
* Uses `MySQL` instead of adatper names where applicable
* Splits type information into adapters code so that the adapter is set
correctly.
* Fix tests that were using mysql2 when they should be abstract
* Add load hook for trilogy to match mysql2
2023-05-09 10:41:27 -04:00
zzak bb98f9a5ec
Merge pull request #48166 from zzak/ar-associations
Several fixes for AR Associations guide
2023-05-09 18:27:35 +09:00
Matt Duszynski b1820c1ec7 Fix ordered list markdown syntax in multi-DB guide 2023-05-09 01:49:07 -05:00
Jonathan Hefner c924ba0df9 Support :message_pack as cookies serializer
This commit adds support for `:message_pack` and `:message_pack_allow_marshal`
as serializers for `config.action_dispatch.cookies_serializer`, just
like `config.active_support.message_serializer`.

The `:message_pack` serializer can fall back to deserializing with
`AS::JSON`, and the `:message_pack_allow_marshal` serializer can fall
back to deserializing with `AS::JSON` or `Marshal`.  Additionally, the
`:marshal`, `:json`, and `:hybrid` / `:json_allow_marshal` serializers
can now fall back to deserializing with `AS::MessagePack`.  These
behaviors make it easier to migrate between cookies serializers.
2023-05-08 15:00:08 -05:00
Jonathan Hefner af6d83521c Support :message_pack as message serializer
This commit adds support for `:message_pack` as a serializer for
`MessageEncryptor` and `MessageVerifier`, and, consequently, as an
option for `config.active_support.message_serializer`.

The `:message_pack` serializer is implemented via
`ActiveSupport::Messages::SerializerWithFallback` and can fall back to
deserializing with `AS::JSON`.  Additionally, the `:marshal`, `:json`,
and `:json_allow_marshal` serializers can now fall back to deserializing
with `AS::MessagePack`.

This commit also adds support for `:message_pack_allow_marshal` as a
serializer, which can fall back to deserializing with `Marshal` as well
as `AS::JSON`.
2023-05-08 14:39:00 -05:00
Jonathan Hefner 4143c0b3e8 Default message serializer to :json_allow_marshal
Prior to this commit, `config.load_defaults 7.1` would cause old
messages (or messages from older apps) to become unreadable, and
developers were encouraged to manually set
`config.active_support.message_serializer = :json_allow_marshal` in
order to prevent this.

This commit changes the default message serializer set by
`config.load_defaults 7.1` from `:json` to `:json_allow_marshal` so that
upgraded apps can continue to read old messages without additional
configuration.

The intention is to eventually change the default to `:json` (with no
`Marshal` fallback) in Rails 7.2, after some time has passed with apps
generating JSON-serialized messages.

Apps can opt in to JSON-only serialization before Rails 7.2 by manually
setting `config.active_support.message_serializer = :json`.

Fixes #48118.
2023-05-08 12:41:53 -05:00
Jonathan Hefner 9fbfd8100b Unify Message{Encryptor,Verifier} serializer config
In #42843 and #42846, several config settings were added to control the
default serializer for `MessageEncryptor` and `MessageVerifier`, and to
provide a migration path from a default `Marshal` serializer to a
default `JSON` serializer:

* `config.active_support.default_message_encryptor_serializer`
  * Supports `:marshal`, `:hybrid`, or `:json`.
* `config.active_support.default_message_verifier_serializer`
  * Supports `:marshal`, `:hybrid`, or `:json`.
* `config.active_support.fallback_to_marshal_deserialization`
  * Affects `:hybrid` for both `MessageEncryptor` and `MessageVerifier`.
* `config.active_support.use_marshal_serialization`
  * Affects `:hybrid` for both `MessageEncryptor` and `MessageVerifier`.

This commit unifies those config settings into a single setting,
`config.active_support.message_serializer`, which supports `:marshal`,
`:json_allow_marshal`, and `:json` values.  So, for example,

  ```ruby
  config.active_support.default_message_encryptor_serializer = :hybrid
  config.active_support.default_message_verifier_serializer = :hybrid
  config.active_support.fallback_to_marshal_deserialization = true
  config.active_support.use_marshal_serialization = false
  ```

becomes

  ```ruby
  config.active_support.message_serializer = :json_allow_marshal
  ```

and

  ```ruby
  config.active_support.default_message_encryptor_serializer = :hybrid
  config.active_support.default_message_verifier_serializer = :hybrid
  config.active_support.fallback_to_marshal_deserialization = false
  config.active_support.use_marshal_serialization = false
  ```

becomes

  ```ruby
  config.active_support.message_serializer = :json
  ```

This commit also replaces `ActiveSupport::JsonWithMarshalFallback` with
`ActiveSupport::Messages::SerializerWithFallback`, which implements a
generic mechanism for serializer fallback.  The `:marshal` serializer
uses this mechanism too, so

  ```ruby
  config.active_support.default_message_encryptor_serializer = :hybrid
  config.active_support.default_message_verifier_serializer = :hybrid
  config.active_support.fallback_to_marshal_deserialization = false
  config.active_support.use_marshal_serialization = true
  ```

becomes

  ```ruby
  config.active_support.message_serializer = :marshal
  ```

Additionally, the logging behavior of `JsonWithMarshalFallback` has been
replaced with notifications which include the names of the intended and
actual serializers, as well as the serialized and deserialized message
data.  This provides a more targeted means of tracking serializer
fallback events.  It also allows the user to "silence" such events, if
desired, without an additional config setting.

All of these changes make it easier to add migration paths for new
serializers such as `ActiveSupport::MessagePack`.
2023-05-08 12:09:45 -05:00
zzak 156f5081fb
Several fixes for AR Associations guide 2023-05-08 17:57:03 +09:00
Hartley McGuire dcf20cbc56
Use "library.name" format in initializer examples
This updates two instances of custom initializer examples in the docs to
use the standard "library.name" format. Previously, one used just "name"
which can lead to hard to debug "cyclic dependency" errors, and the
other used "name.library" which is not the suggested format.
2023-05-07 18:11:16 -04:00
Jean Boussier 89a5d6ada5 Make Active Record's query cache an LRU
I don't know how prevalent this really is, but I heard several time
about users having memory exhaustion issues caused by the query cache
when dealing with long running jobs.

Overall it seems sensible for this cache not to be entirely unbounded.
2023-05-07 11:16:56 +09:00
Jonathan Hefner d7a562eaa3 Document cache_*_multi events [ci-skip]
This adds documentation for the `cache_read_multi.active_support`,
`cache_write_multi.active_support`, and `cache_delete_multi.active_support`
events to the Instrumentation guide.
2023-05-06 16:14:49 -05:00
Jonathan Hefner daa0cb80db Improve cache performance for bare string values
This commit introduces a performance optimization for cache entries with
bare string values such as view fragments.

A new `7.1` cache format has been added which includes the optimization,
and the `:message_pack` cache format now includes the optimization as
well.  (A new cache format is necessary because, during a rolling
deploy, unupgraded servers must be able to read cache entries from
upgraded servers, which means the optimization cannot be enabled for
existing apps by default.)

New apps will use the `7.1` cache format by default, and existing apps
can enable the format by setting `config.load_defaults 7.1`.  Cache
entries written using the `6.1` or `7.0` cache formats can be read when
using the `7.1` format.

**Benchmark**

  ```ruby
  # frozen_string_literal: true
  require "benchmark/ips"

  serializer_7_0 = ActiveSupport::Cache::SerializerWithFallback[:marshal_7_0]
  serializer_7_1 = ActiveSupport::Cache::SerializerWithFallback[:marshal_7_1]
  entry = ActiveSupport::Cache::Entry.new(Random.bytes(10_000), version: "123")

  Benchmark.ips do |x|
    x.report("dump 7.0") do
      $dumped_7_0 = serializer_7_0.dump(entry)
    end

    x.report("dump 7.1") do
      $dumped_7_1 = serializer_7_1.dump(entry)
    end

    x.compare!
  end

  Benchmark.ips do |x|
    x.report("load 7.0") do
      serializer_7_0.load($dumped_7_0)
    end

    x.report("load 7.1") do
      serializer_7_1.load($dumped_7_1)
    end

    x.compare!
  end
  ```

  ```
  Warming up --------------------------------------
              dump 7.0     5.482k i/100ms
              dump 7.1    10.987k i/100ms
  Calculating -------------------------------------
              dump 7.0     73.966k (± 6.9%) i/s -    367.294k in   5.005176s
              dump 7.1    127.193k (±17.8%) i/s -    615.272k in   5.081387s

  Comparison:
              dump 7.1:   127192.9 i/s
              dump 7.0:    73966.5 i/s - 1.72x  (± 0.00) slower

  Warming up --------------------------------------
              load 7.0     7.425k i/100ms
              load 7.1    26.237k i/100ms
  Calculating -------------------------------------
              load 7.0     85.574k (± 1.7%) i/s -    430.650k in   5.034065s
              load 7.1    264.877k (± 1.6%) i/s -      1.338M in   5.052976s

  Comparison:
              load 7.1:   264876.7 i/s
              load 7.0:    85573.7 i/s - 3.10x  (± 0.00) slower
  ```

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2023-05-04 16:10:22 -05:00
Jonathan Hefner e2524e574b Support :message_pack as a cache serializer format
This commit adds support for `:message_pack` as an option for
`config.active_support.cache_format_version`.

Cache entries written using the `6.1` or `7.0` formats can be read when
using the `:message_pack` format. Additionally, cache entries written
using the `:message_pack` format can now be read when using the `6.1` or
`7.0` format. These behaviors makes it easy to migrate between formats
without invalidating the entire cache.
2023-05-03 14:22:20 -05:00
Yasuo Honda 2a7cd759be
Merge pull request #48085 from wpank84/patch-1
Update migration examples to showcase database-agnostic raw SQL execution
2023-04-29 07:14:13 +09:00
wpankonien 11efa0445d Update migration example to showcase database-agnostic raw SQL execution 2023-04-28 10:04:13 -05:00