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:
@@ -89,7 +89,7 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
end
|
||||
|
||||
def bulk_update_request_link
|
||||
%{"bulk update request ##{id}":/bulk_update_requests?search%5Bid%5D=#{id}}
|
||||
%{"bulk update request ##{id}":#{Routes.bulk_update_requests_path(search: { id: id })}}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class Comment < ApplicationRecord
|
||||
mentionable(
|
||||
:message_field => :body,
|
||||
:title => ->(user_name) {"#{creator.name} mentioned you in a comment on post ##{post_id}"},
|
||||
:body => ->(user_name) {"@#{creator.name} mentioned you in a \"comment\":/posts/#{post_id}#comment-#{id} on post ##{post_id}:\n\n[quote]\n#{DText.extract_mention(body, "@" + user_name)}\n[/quote]\n"}
|
||||
:body => ->(user_name) {"@#{creator.name} mentioned you in a \"comment\":#{Routes.post_path(post, anchor: "comment-#{id}")} on post ##{post_id}:\n\n[quote]\n#{DText.extract_mention(body, "@" + user_name)}\n[/quote]\n"}
|
||||
)
|
||||
|
||||
module SearchMethods
|
||||
|
||||
@@ -28,7 +28,7 @@ class ForumPost < ApplicationRecord
|
||||
mentionable(
|
||||
:message_field => :body,
|
||||
:title => ->(user_name) {%{#{creator.name} mentioned you in topic ##{topic_id} (#{topic.title})}},
|
||||
:body => ->(user_name) {%{@#{creator.name} mentioned you in topic ##{topic_id} ("#{topic.title}":[/forum_topics/#{topic_id}?page=#{forum_topic_page}]):\n\n[quote]\n#{DText.extract_mention(body, "@" + user_name)}\n[/quote]\n}}
|
||||
:body => ->(user_name) {%{@#{creator.name} mentioned you in topic ##{topic_id} ("#{topic.title}":[#{Routes.forum_topic_path(topic, page: forum_topic_page)}]):\n\n[quote]\n#{DText.extract_mention(body, "@" + user_name)}\n[/quote]\n}}
|
||||
)
|
||||
|
||||
module SearchMethods
|
||||
|
||||
@@ -1390,7 +1390,8 @@ class Post < ApplicationRecord
|
||||
|
||||
new_artist_tags.each do |tag|
|
||||
if tag.artist.blank?
|
||||
warnings.add(:base, "Artist [[#{tag.name}]] requires an artist entry. \"Create new artist entry\":[/artists/new?artist%5Bname%5D=#{CGI.escape(tag.name)}]")
|
||||
new_artist_path = Routes.new_artist_path(artist: { name: tag.name })
|
||||
warnings.add(:base, "Artist [[#{tag.name}]] requires an artist entry. \"Create new artist entry\":[#{new_artist_path}]")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1412,7 +1413,8 @@ class Post < ApplicationRecord
|
||||
return if tags.any?(&:artist?)
|
||||
return if Sources::Strategies.find(source).is_a?(Sources::Strategies::Null)
|
||||
|
||||
warnings.add(:base, "Artist tag is required. \"Create new artist tag\":[/artists/new?artist%5Bsource%5D=#{CGI.escape(source)}]. Ask on the forum if you need naming help")
|
||||
new_artist_path = Routes.new_artist_path(artist: { source: source })
|
||||
warnings.add(:base, "Artist tag is required. \"Create new artist tag\":[#{new_artist_path}]. Ask on the forum if you need naming help")
|
||||
end
|
||||
|
||||
def has_copyright_tag
|
||||
|
||||
@@ -8,10 +8,10 @@ class UserFeedback < ApplicationRecord
|
||||
validates_inclusion_of :category, :in => %w(positive negative neutral)
|
||||
after_create :create_dmail, unless: :disable_dmail_notification
|
||||
after_update(:if => ->(rec) { CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log(%{#{CurrentUser.name} updated user feedback for "#{rec.user.name}":/users/#{rec.user_id}}, :user_feedback_update)
|
||||
ModAction.log(%{#{CurrentUser.name} updated user feedback for "#{rec.user.name}":#{Routes.user_path(rec.user)}}, :user_feedback_update)
|
||||
end
|
||||
after_destroy(:if => ->(rec) { CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log(%{#{CurrentUser.name} deleted user feedback for "#{rec.user.name}":/users/#{rec.user_id}}, :user_feedback_delete)
|
||||
ModAction.log(%{#{CurrentUser.name} deleted user feedback for "#{rec.user.name}":#{Routes.user_path(rec.user)}}, :user_feedback_delete)
|
||||
end
|
||||
|
||||
deletable
|
||||
@@ -52,7 +52,7 @@ class UserFeedback < ApplicationRecord
|
||||
end
|
||||
|
||||
def create_dmail
|
||||
body = %{#{disclaimer}@#{creator.name} created a "#{category} record":/user_feedbacks?search[user_id]=#{user_id} for your account:\n\n#{self.body}}
|
||||
body = %{#{disclaimer}@#{creator.name} created a "#{category} record":#{Routes.user_feedbacks_path(search: { user_id: user_id })} for your account:\n\n#{self.body}}
|
||||
Dmail.create_automated(:to_id => user_id, :title => "Your user record has been updated", :body => body)
|
||||
end
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user