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

@@ -32,20 +32,7 @@ module Notifications
end
def path_for(resource)
nested_path_for(resource) || url_for([resource, only_path: true])
end
def nested_path_for(resource)
case resource.class.name
when "Legislation::Question"
legislation_process_question_path(resource.process, resource)
when "Legislation::Proposal"
legislation_process_proposal_path(resource.process, resource)
when "Budget::Investment"
budget_investment_path(resource.budget, resource)
else
false
end
polymorphic_hierarchy_path(resource)
end
def error_message(resource_model = nil)