Skip to content

Commit 04e1a0d

Browse files
committed
Add documentation for rails#43487
In rails#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.
1 parent d1461cd commit 04e1a0d

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)