diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-04 01:25:24 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-04 01:25:24 +0200 |
| commit | 4596b32a0787a574881284d042bb77c970df8a4d (patch) | |
| tree | 930e1d174f73e92e7bc70bc3da17a2d334ff57cd /app | |
| parent | 206dc5c50a73c5402b90d7fdc8945d3ba9356758 (diff) | |
Fix safe_return_to being uncallable from controllers
Defined only in ApplicationHelper, which Rails auto-mixes into views
but not controllers - so events#create and events#update, which call
it directly, have been broken since introduction. Likely unexercised
until now because every existing event was created via
node.events.create! in the seed script, never through a real POST.
Moved to ApplicationController as a protected method + helper_method
declaration, so both controllers and views can call it (form_error_
messages stays in ApplicationHelper - it's genuinely view-only,
content_tag isn't available in a controller either). Logic unchanged,
caught by the new EventsController tests in the previous commit.
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/application_controller.rb | 12 | ||||
| -rw-r--r-- | app/helpers/application_helper.rb | 10 |
2 files changed, 12 insertions, 10 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 75f92c3..cbeb40d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb | |||
| @@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base | |||
| 5 | 5 | ||
| 6 | before_action :set_locale | 6 | before_action :set_locale |
| 7 | 7 | ||
| 8 | helper_method :safe_return_to | ||
| 9 | |||
| 8 | protected | 10 | protected |
| 9 | 11 | ||
| 10 | def set_locale | 12 | def set_locale |
| @@ -18,4 +20,14 @@ class ApplicationController < ActionController::Base | |||
| 18 | def default_url_options | 20 | def default_url_options |
| 19 | { locale: I18n.locale == I18n.default_locale ? nil : I18n.locale } | 21 | { locale: I18n.locale == I18n.default_locale ? nil : I18n.locale } |
| 20 | end | 22 | end |
| 23 | |||
| 24 | def safe_return_to(url) | ||
| 25 | return events_path if url.blank? | ||
| 26 | uri = URI.parse(url) | ||
| 27 | return events_path if uri.host.present? | ||
| 28 | return events_path unless url.start_with?('/') | ||
| 29 | url | ||
| 30 | rescue URI::InvalidURIError | ||
| 31 | events_path | ||
| 32 | end | ||
| 21 | end | 33 | end |
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 72b76b8..0be66e9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb | |||
| @@ -11,14 +11,4 @@ module ApplicationHelper | |||
| 11 | end | 11 | end |
| 12 | end | 12 | end |
| 13 | end | 13 | end |
| 14 | |||
| 15 | def safe_return_to(url) | ||
| 16 | return events_path if url.blank? | ||
| 17 | uri = URI.parse(url) | ||
| 18 | return events_path if uri.host.present? | ||
| 19 | return events_path unless url.start_with?('/') | ||
| 20 | url | ||
| 21 | rescue URI::InvalidURIError | ||
| 22 | events_path | ||
| 23 | end | ||
| 24 | end | 14 | end |
