Extract commentable_path to an initializer

By doing so and including it in ActionDispatch::Routing::UrlFor, we make
it available in controllers, helpers and specs, and so we can remove the
duplication we had there with methods dealing with the same problem.

Even if monkey-patching is ugly, using a different module and executing
ActionDispatch::Routing::UrlFor.send(:include, MyModule) wouldn't make
the method available in the controller.
This commit is contained in:
Javi Martín
2018-09-17 20:16:54 +02:00
parent b49b3ade68
commit a64a290392
4 changed files with 63 additions and 41 deletions

View File

@@ -36,19 +36,11 @@ class NotificationsController < ApplicationController
end
private
def linkable_resource_path(notification)
case notification.linkable_resource.class.name
when "Budget::Investment"
budget_investment_path @notification.linkable_resource.budget, @notification.linkable_resource
when "Topic"
community_topic_path @notification.linkable_resource.community, @notification.linkable_resource
if notification.linkable_resource.is_a?(AdminNotification)
notification.linkable_resource.link || notifications_path
else
if @notification.linkable_resource.is_a?(AdminNotification)
@notification.linkable_resource.link || notifications_path
else
url_for @notification.linkable_resource
end
polymorphic_hierarchy_path(notification.linkable_resource)
end
end