diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-06-03 12:34:00 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-06-05 10:56:04 +0100 |
commit | 6bd0bfe7599aee4e55bdd63196d1e2c5cc80129c (patch) | |
tree | a63a36c11b90f369c7c56781ed79a40d9a9a11a6 /app/helpers/link_to_helper.rb | |
parent | fee5d9384862af086613c4f09e0fd96f7bd347b8 (diff) |
Remove duplication from new correspondence urls
Diffstat (limited to 'app/helpers/link_to_helper.rb')
-rwxr-xr-x | app/helpers/link_to_helper.rb | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 9f63ec583..e5ef2ca39 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -28,23 +28,19 @@ module LinkToHelper # Incoming / outgoing messages def incoming_message_url(incoming_message, options = {}) - default_options = { :anchor => "incoming-#{ incoming_message.id }", - :nocache => "incoming-#{ incoming_message.id }" } - request_url(incoming_message.info_request, options.merge(default_options)) + message_url(incoming_message, options) end def incoming_message_path(incoming_message) - incoming_message_url(incoming_message, :only_path => true) + message_path(incoming_message) end def outgoing_message_url(outgoing_message, options = {}) - default_options = { :anchor => "outgoing-#{ outgoing_message.id }", - :nocache => "outgoing-#{ outgoing_message.id }" } - request_url(outgoing_message.info_request, options.merge(default_options)) + message_url(outgoing_message, options) end def outgoing_message_path(outgoing_message) - outgoing_message_url(outgoing_message, :only_path => true) + message_path(outgoing_message) end def comment_url(comment, options = {}) @@ -352,5 +348,24 @@ module LinkToHelper return url_for(params) end + private + + # Private: Generate a request_url linking to the new correspondence + def message_url(message, options = {}) + message_type = message.class.to_s.gsub('Message', '').downcase + + default_options = { :anchor => "#{ message_type }-#{ message.id }" } + + if options.delete(:cachebust) + default_options.merge!(:nocache => "#{ message_type }-#{ message.id }") + end + + request_url(message.info_request, options.merge(default_options)) + end + + def message_path(message) + message_url(message, :only_path => true) + end + end |