Commit Graph

526 Commits

Author SHA1 Message Date
zzak
e3c73fd183
Replace all occurrences of '<tt>(\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>ActiveRecord::Base</tt> -> +ActiveRecord::Base+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-05-25 06:52:32 +09:00
Hartley McGuire
b3c6a9adf0
Remove explicit "aliased as" documentation
Most of these are redundant because rdoc handles these itself, but
`titlecase` on `ActiveSupport::Inflector` does not exist so that one is
just incorrect.
2023-05-18 11:04:04 -04:00
Petrik
f89588240f Escape namespaces in some doc headers [ci-skip]
Also move the CSP header from a method to the module.
2023-04-24 09:18:08 +02:00
Petrik
48b205989a Cleanup Action Pack documentation headers [ci-skip] 2023-04-22 20:40:39 +02:00
Petrik
c0d501e818 Fix some doc headings naming [ci-skip]
Headings should use the name of library instead of the namespace.
2023-04-21 10:15:47 +02:00
Petrik
168c206e06 Add missing headers to Action Pack docs [ci-skip]
Having a h1 heading will improve SEO and makes things look more consistent.
2023-04-20 22:24:43 +02:00
Hartley McGuire
ada584bcb8
Deprecate AbstractController MissingHelperError
This error used to be a wrapper for a LoadError raised when
require_dependency was used to load helpers for controllers.

Since Zeitwerk does not use require_dependency, the only usage of the
error was removed in 5b28a0e972da31da570ed24be505ef7958ab4b5e.
2023-01-31 02:49:21 -05:00
Jonathan Hefner
aaf7bed003 Document ActionController::Rendering#render [ci-skip]
In #33418, documentation from `ActionView::Helpers::RenderingHelper#render`
was copied to `ActionController::Renderer#render` with the intention of
documenting `ActionController::Rendering#render`.  Since then, further
documentation has been added to `ActionController::Renderer#render`, and
`ActionController::Renderer#render` has been mistaken for
`ActionController::Rendering#render` (for example, in #46045).

This commit adds documentation to `ActionController::Rendering#render`
(which was previously `:nodoc:` because it is a simple override of
`AbstractController::Rendering#render`), and updates related
documentation to point to `ActionController::Rendering#render`.
2023-01-08 15:47:31 -06:00
Jonathan Hefner
cfe300ceb1 Format inline code [ci-skip] 2023-01-08 15:47:20 -06:00
Jonathan Hefner
3eadf057db Fix typos in API docs [ci-skip] 2023-01-08 15:47:20 -06:00
Jonathan Hefner
33557c5dca Indent private methods in code examples [ci-skip]
This matches the indentation used in generated code, such as code from
`railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt`.
2023-01-08 15:47:20 -06:00
Junichi Sato
6f1f2d74e6
Tweak doc to show helper methods need not be public [ci-skip] 2023-01-05 16:19:36 +09:00
eileencodes
04e1a0d2e1
Add documentation for #43487
In #43487 we missed adding a changelog so that's been added here. In
addition, since this isn't a new framework default unless you are
creating a new application (and only in dev and test environments by
default) it can be easy to miss this new option. I've updated the
message to mention the option following DHH's suggestion on the original
PR.
2023-01-03 13:40:28 -05:00
Jonathan Hefner
7bcca5b763 Use memoized dup of url_helpers for reinclusion
In the case where a controller subclasses an engine's controller that,
in turn, subclasses a controller that includes the application's
`url_helpers` (for example, in the "isolated engine routes and helpers
are isolated to that engine" test in `railties/test/railties/engine_test.rb`),
this commit avoids allocating a new module per controller:

  ```ruby
  ActionController::Base.include Rails.application.routes.url_helpers
  C1 = Class.new(ActiveStorage::DirectUploadsController)
  C2 = Class.new(ActiveStorage::DirectUploadsController)

  C1.ancestors - C2.ancestors
  # BEFORE:
  # => [C1, #<Module:0x...>]
  # AFTER:
  # => [C1]
  ```

This commit also modifies the `RouteHelperIntegrationTest` test to use
the controllers defined in `actionpack/test/abstract_unit.rb`.
Otherwise, `extend AbstractController::Railties::RoutesHelpers.with(...)`
happens twice -- once for `ActionController::Base` and once for
`FakeACBase` -- which causes `FooController` to include an extra module
as it flip-flops its `_routes` definition.  Previously, the extra module
only defined a `_routes` method; now, the extra module would be the
memoized dup of `routes.url_helpers`, which would cause the "only
includes one module with route helpers" test to falsely fail.
2022-11-19 10:57:21 -06:00
Jonathan Hefner
b287779499 Add {Abstract,Action}Controller.deprecator
This commit adds `AbstractController.deprecator` and
`ActionController.deprecator`, and replaces all usages of
`ActiveSupport::Deprecation.warn` in `actionpack/lib/action_controller`
with the latter.

Additionally, this commit adds `ActionController.deprecator` to
`Rails.application.deprecators`.  Because `AbstractController` does not
have its own railtie to do the same, `AbstractController` and
`ActionController` use the same deprecator instance.  Thus, both can be
configured via `Rails.application.deprecators[:action_controller]` or
via config settings such as `config.active_support.report_deprecations`.
2022-10-27 16:20:53 -05:00
Ryo Nakamura
a5065d4abc Avoid using render(...) and return in example code 2022-09-02 06:33:43 +09:00
Jonathan Hefner
32c169d014 Linkify code references [ci-skip] 2022-08-05 21:36:18 -05:00
Jonathan Hefner
7415b93580 Avoid ActionController on ActionMailer::Base load
This refactor avoids unnecessarily loading `ActionController::Base` when
loading `ActionMailer::Base`.

Before:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ ActionMailer::Base } }'
Calculating -------------------------------------
                load    10.013M memsize (     1.372M retained)
                        78.341k objects (    14.363k retained)
                        50.000  strings (    50.000  retained)
```

After:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ ActionMailer::Base } }'
Calculating -------------------------------------
                load     5.043M memsize (   729.741k retained)
                        38.854k objects (     7.809k retained)
                        50.000  strings (    50.000  retained)
```
2022-05-20 11:57:34 -05:00
Alex Ghiculescu
203032dd76 Fix incorrect line number if a helper_method errors
Currently if you use `helper_method` to define a method, and inside that method you get an error, the backtrace is off by one line.

This PR fixes that so that the backtrace now points to the line where you called `helper_method`.
2022-05-17 15:41:28 -05:00
Ryuta Kamizono
714fd07fd9 All intermediate delegation methods should preserve kwargs flag
Since 0456826180,
`foo(*caller_args)` method call delegation no longer preserve kwargs
flag.

Fixes #44846.
2022-04-06 15:32:54 +09:00
Jean Boussier
2fd34270eb Eager load controllers view_context_class
These classes are relatively small, however they include lots of
modules as helpers. And if any of the included module hold constants
including it cause the global constant cache to be invalidated
which is really bad for performance.

So when eager loading is enabled we create all the possible classes
as part of the application boot.
2022-03-02 08:47:54 +01:00
Jonathan Hefner
a199aaedb8 Cross-link API docs [ci-skip]
RDoc will automatically format and link API references as long as they
are not already marked up as inline code.

This commit removes markup from various API references so that those
references will link to the relevant API docs.
2022-02-21 11:45:25 -06:00
Jonathan Hefner
5fdbd217d1 Fix typos [ci-skip] 2022-02-21 11:11:11 -06:00
Jess Bees
60f7d49033 Raise error when callback's only/unless symbols aren't methods
When `before_action :callback, only: :action_name` is declared on a
controller that doesn't respond to `action_name`, raise an exception
at request time. This is a safety measure to ensure that typos or
forgetfulness don't prevent a crucial callback from being run when it
should.

Include names of filters for more useful error messages

The error message of the raised exception will be more useful if it
indicates the names of the callbacks that have the missing conditinoal
action.

The way the callbacks get shoehorned into `_normalize_callback_options`
options parameter is a little awkward, but done this way to avoid
changing the method's signature, since it is a publicly documented
method.
2021-12-14 15:22:08 -05:00
Rafael Mendonça França
7160f46a9e
Merge pull request #43368 from FestaLab/render-hash-syntax
Replaces the hash rocket operator in favor of the newer Ruby syntax on render
2021-12-08 18:13:44 -05:00
Jean Boussier
e974c58bf9 Set the execution context from AC::Metal rather than AbstractController
The later is used by totally different codepaths such as mailers.

Fix: https://github.com/rails/rails/pull/43598
2021-11-15 15:36:28 +01:00
Jean Boussier
6bad959565 Extract ActiveSupport::ExecutionContext out of ActiveRecord::QueryLogs
I'm working on a standardized error reporting interface
(https://github.com/rails/rails/issues/43472) and it has the same need
for a `context` than Active Record's query logs.

Just like query logs, when reporting an error you want to know what the
current controller or job is, etc.

So by extracting it we can allow both API to use the same store.
2021-11-10 09:36:02 +01:00
John Hawthorn
e7fb2b114e Mark ActionFilter as nodoc
Didn't intend for this to be public. Oops!
2021-10-13 15:14:46 -07:00
Rafael Mendonça França
28bc4f87fd
Extract common behavior of html safe translation to a module
This module will be a private module in Active Support, this way
if we need to change the behavior of translate in controllers or
views don't forget to change in the other one.
2021-10-12 18:03:46 +00:00
Rafael Mendonça França
a5247bb908
Treat html suffix in controller translation
There are some difference between translation in a view and translation
in a controller.
This will treat html suffix in controller translation.

Closes #27862.

Co-authored-by: Rui Onodera <deraru@gmail.com>
Co-authored-by: Gavin Miller <gavingmiller@gmail.com>
2021-10-08 21:21:53 +00:00
Liuri Loami
d3e5833459 Replaces the "hash rocket" operator in favor of the newer Ruby syntax when rendering on render 2021-10-03 23:33:56 -03:00
John Hawthorn
b3024484ab Avoid instance_exec for controller callbacks
When a proc is passed to a callback (either as a condition or as the
callback itself) it is evaluated using instance_exec on the controller
instance. Calling instance_exec creates a new singleton class for the
object, which then will require new inline method caches.

This commit avoids creating the extra controller singleton classes when
:only or :except are passed to a callback.
2021-09-29 14:31:47 -07:00
Jean Boussier
c91c266872 Enable Style/ExplicitBlockArgument cop
This reduce the stack size which is beneficial for
exceptions performance.

See: https://gist.github.com/byroot/cb3bcadcc3701c2518d002fb8d3a4e7a

However the cop is unsafe because it might change the block arity,
so it can run into some false positives.
2021-09-05 17:06:19 +02:00
Xavier Noria
d4ab55e901 Delete orphan requires in AS::Dependencies 2021-08-19 00:14:06 +02:00
Ryuta Kamizono
0740772653 Fix generated MIME methods to recognize kwargs
Without this fix, generated MIME methods can't recognize kwargs:

```
% bin/test -w test/abstract/collector_test.rb:53
Running 5 tests in a single process (parallelization threshold is 50)
Run options: --seed 56716

# Running:

F

Failure:
AbstractController::Testing::TestCollector#test_generated_methods_call_custom_with_arguments_received [/Users/kamipo/src/github.com/rails/rails/actionpack/test/abstract/collector_test.rb:59]:
--- expected
+++ actual
@@ -1 +1 @@
-[#<Mime::Type:0xXXXXXX @synonyms=[], @symbol=:text, @string="text/plain", @hash=-3828881190283196326>, [:foo], {:bar=>:baz}, nil]
+[#<Mime::Type:0xXXXXXX @synonyms=[], @symbol=:text, @string="text/plain", @hash=-3828881190283196326>, [:foo, {:bar=>:baz}], {}, nil]
```
2021-08-07 13:59:08 +09:00
Rafael Mendonça França
18707ab17f
Standardize nodoc comments 2021-07-29 21:18:07 +00:00
Ryuta Kamizono
5f45aeaaae :nodoc: for corrections
Like all others for corrections already does.
2021-07-05 17:59:22 +09:00
Petrik
0409ed57ac Clean up checks to see if DidYouMean is defined
As of Ruby 2.7 DidYouMean is included as a default gem, so there is no
need to check if DidYouMean is defined in the test suite. We still need
to check if the DidYouMean modules are defined in the actual code, as
someone might run Rails with DidYouMean disabled by using the
`--disable-did_you_mean` flag. This is ussually done for performance
reasons.

This commit also includes some of the changes made by Yuki in:
https://github.com/rails/rails/pull/39555
These changes include replacing Jaro with the more accurate
SpellChecker, and using DidYouMean::Correctable for simplere
corrections.

The DidYouMean::SpellChecker does have a treshold for corrections.
If there is not enough similarity it might not return a suggestion.
To stop the tests from failing some test data had to be changed.

For example, `non_existent` does not meet the treshold for `hello`, but
`ello` does:

DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('non_existent')
=> []
DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('ello')
=> ["hello"]

The treshold makes sense for spelling errors. But maybe we should add a
different SpellChecker that helps to get a suggestion even if there is
little overlap. For example for when a model only has 2 attributes
(title and body), it's helpful to get a suggestion for `name`

Co-Authored-By: Yuki Nishijima <yk.nishijima@gmail.com>
2021-07-04 13:43:50 +02:00
Étienne Barrié
5a471b6d8f Keep process_action private when redefined
AbstractController::Base defines process_action as private, but modules
included after redefine it as a public method.
2021-05-13 14:14:24 -04:00
Matheus Richard
c3d7794f16 Replace map + compact with filter_map 2021-04-22 22:08:34 -03:00
Rafael Mendonça França
94b954576a
Autocorrect Rubocop roles 2021-04-13 18:32:25 +00:00
Rafael Mendonça França
4354e3ae49
Don't define methods using the method modifier in the same line as the method
Our style guide use block method modifiers, not inline method modifiers.
2021-04-12 18:49:54 +00:00
Jean Boussier
3f59640016 Stop checking if ruby2_keywords is defined 2021-04-11 13:42:02 +02:00
John Hawthorn
d6ca73306c Force _routes to be redefined on re-inclusion
This fixes an regression where _routes were set incorrectly when the
inheritance chain went from one route namespace (isolated engine or main
app) to another and then back to the original. Because the url_helpers
module was being cached and was being re-included this was not setting
_routes.

This commit solves the issue by detecting that case and redefining
_routes in that case. We could have always performed the redefinition,
but it's a pretty uncommon case, so we might as well only do it when
necessary.
2021-02-16 11:55:22 -08:00
Ryuta Kamizono
7b680baea2 Remove require "active_support/core_ext/symbol/starts_ends_with"
Ruby 2.7 has native `Symbol#start_with?` and `Symbol#end_with?`.
2021-02-09 22:31:09 +09:00
Jan Klimo
0c1028f4bb Fix nil translation key lookup in controllers 2020-12-22 21:17:51 +07:00
John Hawthorn
758ad13c58 Avoid creating helper modules until modified
In applications which use :all helpers (the default), most controllers
won't be making modifications to their _helpers module.

In CRuby this created many ICLASS objects which could cause a large
increase in memory usage in applications with many controllers and
helpers.

To avoid creating unnecessary modules this PR builds modules only when a
modification is being made: ethier by calling `helper`, `helper_method`,
or through having a default helper (one matching the controller's name)
included onto it.
2020-09-08 16:55:53 -07:00
Petrik
080edb444a Shorten inspect on AbstractController::Base
Calling self in an action of a controller generates an endless stream of
characters, including the request object and all instances variables.
This can be frustrating when using a debugger in a controller and
accidentally calling `self` generates output for a couple of seconds.

This shortens inspect to only show the class name.

    MyController.new.inspect # => "#<MyController:0x00000000005028>"
2020-09-05 19:37:31 +02:00
fatkodima
e24d6ecbfd Update rubocop-performance gem and enable Performance/DeletePrefix and Performance/DeleteSuffix cops 2020-05-24 12:51:35 +03:00
fatkodima
6c4f3be929 Unify raise_on_missing_translations for views and controllers 2020-05-20 02:42:59 +03:00