Skip to content

Commit 6016390

Browse files
authored
Merge pull request rails#46877 from eileencodes/minor-improvements-to-pr-43487
Add documentation for rails#43487
2 parents 6f3c966 + 04e1a0d commit 6016390

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

actionpack/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* Allow raising an error when a callback's only/unless symbols aren't existing methods.
2+
3+
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.
4+
5+
For new applications, raising an error for undefined actions is turned on by default. If you do not want to opt-in to this behavior set `config.action_pack.raise_on_missing_callback_actions` to `false` in your application configuration. See #43487 for more details.
6+
7+
*Jess Bees*
8+
19
* Allow cookie options[:domain] to accept a proc to set the cookie domain on a more flexible per-request basis
210

311
*RobL*

actionpack/lib/abstract_controller/callbacks.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ def match?(controller)
4848
missing_action = @actions.find { |action| !controller.available_action?(action) }
4949
if missing_action
5050
filter_names = @filters.length == 1 ? @filters.first.inspect : @filters.inspect
51-
message = "The #{missing_action} action could not be found for the #{filter_names} callback on #{controller.class.name}, but it is listed in its #{@conditional_key.inspect} option"
51+
52+
message = <<~MSG
53+
The #{missing_action} action could not be found for the #{filter_names}
54+
callback on #{controller.class.name}, but it is listed in the controller's
55+
#{@conditional_key.inspect} option.
56+
57+
Raising for missing callback actions is a new default in Rails 7.1, if you'd
58+
like to turn this off you can delete the option from the environment configurations
59+
or set `config.action_pack.raise_on_missing_callback_actions` to `false`.
60+
MSG
61+
5262
raise ActionNotFound.new(message, controller, missing_action)
5363
end
5464
end

0 commit comments

Comments
 (0)