Module: BugReportsClient::MainAppRoutes
- Defined in:
- lib/bug_reports_client/main_app_routes.rb
Overview
Included into engine views (via the engine's ApplicationController) so
host layouts render unmodified inside engine pages. Isolated engines
resolve route helpers against their own routes, which breaks host-only
helpers (root_path, profile_path, etc) used in host layouts and navbars.
This delegates any unknown *_path / *_url helper to the host app, while
the engine's own helpers keep resolving first because they are real
methods and never reach method_missing.
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/bug_reports_client/main_app_routes.rb', line 10
def method_missing(method, *args, &block)
if main_app_route_helper?(method)
main_app.public_send(method, *args)
else
super
end
end
|
Class Method Details
.active_storage_argument?(argument) ⇒ Boolean
52
53
54
55
56
57
58
59
60
|
# File 'lib/bug_reports_client/main_app_routes.rb', line 52
def self.active_storage_argument?(argument)
return false unless defined?(ActiveStorage)
argument.is_a?(ActiveStorage::Blob) ||
argument.is_a?(ActiveStorage::Attachment) ||
argument.is_a?(ActiveStorage::Variant) ||
argument.is_a?(ActiveStorage::VariantWithRecord) ||
argument.is_a?(ActiveStorage::Preview)
end
|
Instance Method Details
#polymorphic_path(record, options = {}) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/bug_reports_client/main_app_routes.rb', line 44
def polymorphic_path(record, options = {})
if MainAppRoutes.active_storage_argument?(record)
main_app.polymorphic_path(record, options)
else
super
end
end
|
#polymorphic_url(record, options = {}) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/bug_reports_client/main_app_routes.rb', line 36
def polymorphic_url(record, options = {})
if MainAppRoutes.active_storage_argument?(record)
main_app.polymorphic_url(record, options)
else
super
end
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
18
19
20
|
# File 'lib/bug_reports_client/main_app_routes.rb', line 18
def respond_to_missing?(method, include_private = false)
main_app_route_helper?(method) || super
end
|
#url_for(argument = nil) ⇒ Object
Active Storage URLs (blobs, attachments, variants - e.g. a user avatar
in a host navbar, or image_tag on an attachment) resolve through
polymorphic mappings that only exist on the HOST's route set, so route
them there explicitly. image_tag goes through polymorphic_url, other
callers through url_for - cover all three. Everything else keeps the
normal lookup.
28
29
30
31
32
33
34
|
# File 'lib/bug_reports_client/main_app_routes.rb', line 28
def url_for(argument = nil)
if MainAppRoutes.active_storage_argument?(argument)
main_app.polymorphic_path(argument)
else
super
end
end
|