aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2014-10-20 10:24:53 +0100
committerGareth Rees <gareth@mysociety.org>2014-10-29 13:01:11 +0000
commitb14fd2456ad209d9d6578388819249712e6c6d75 (patch)
treef1dea373df0d630b877952a02a49a4429b96c4b2
parent32c019bbae4995bc105c6813a4f839adf2805542 (diff)
Move Comment class method to top of file
-rw-r--r--app/models/comment.rb30
1 files changed, 15 insertions, 15 deletions
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 84674cd91..a286aa1f5 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -33,6 +33,21 @@ class Comment < ActiveRecord::Base
after_save :event_xapian_update
+ # When posting a new comment, use this to check user hasn't double
+ # submitted.
+ def self.find_existing(info_request_id, body)
+ # TODO: can add other databases here which have regexp_replace
+ if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
+ # Exclude spaces from the body comparison using regexp_replace
+ regex_replace_sql = "regexp_replace(body, '[[:space:]]', '', 'g') = regexp_replace(?, '[[:space:]]', '', 'g')"
+ Comment.where(["info_request_id = ? AND #{ regex_replace_sql }", info_request_id, body ]).first
+ else
+ # For other databases (e.g. SQLite) not the end of the world being
+ # space-sensitive for this check
+ Comment.where(:info_request_id => info_request_id, :body => body).first
+ end
+ end
+
def body
ret = read_attribute(:body)
return ret if ret.nil?
@@ -60,21 +75,6 @@ class Comment < ActiveRecord::Base
text.html_safe
end
- # When posting a new comment, use this to check user hasn't double
- # submitted.
- def self.find_existing(info_request_id, body)
- # TODO: can add other databases here which have regexp_replace
- if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
- # Exclude spaces from the body comparison using regexp_replace
- regex_replace_sql = "regexp_replace(body, '[[:space:]]', '', 'g') = regexp_replace(?, '[[:space:]]', '', 'g')"
- Comment.where(["info_request_id = ? AND #{ regex_replace_sql }", info_request_id, body ]).first
- else
- # For other databases (e.g. SQLite) not the end of the world being
- # space-sensitive for this check
- Comment.where(:info_request_id => info_request_id, :body => body).first
- end
- end
-
def for_admin_column
self.class.content_columns.each do |column|
yield(column.human_name, send(column.name), column.type.to_s, column.name)