routes: replace hardcoded routes in models with route helpers.

Add a Routes module that gives models access to route helpers outside of
views, and use it to replace various hardcoded routes.
This commit is contained in:
evazion
2020-12-23 13:19:03 -06:00
parent a947a10c53
commit dbb66ace90
13 changed files with 34 additions and 21 deletions

View File

@@ -122,7 +122,7 @@ class WikiPage < ApplicationRecord
broken_wikis = WikiPage.linked_to(title_was)
if broken_wikis.count > 0
broken_wiki_search = Rails.application.routes.url_helpers.wiki_pages_path(search: { linked_to: title_was })
broken_wiki_search = Routes.wiki_pages_path(search: { linked_to: title_was })
warnings.add(:base, %!Warning: [[#{title_was}]] is still linked from "#{broken_wikis.count} #{"other wiki page".pluralize(broken_wikis.count)}":[#{broken_wiki_search}]. Update #{(broken_wikis.count > 1) ? "these wikis" : "this wiki"} to link to [[#{title}]] instead!)
end
end