diff options
author | Henare Degan <henare.degan@gmail.com> | 2013-01-25 15:11:02 +1100 |
---|---|---|
committer | Henare Degan <henare.degan@gmail.com> | 2013-01-25 15:11:02 +1100 |
commit | ac2f058c50a4cfca40be06a7090cb6fe0527c04a (patch) | |
tree | 696b38e9a6fc2980fa65e6e2364db938e1070849 | |
parent | a3bc84217bd3b7b8ffc279405629db33edcbe587 (diff) |
Comment model - Overwriting validate is deprecated in Rails 3
-rw-r--r-- | app/models/comment.rb | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/app/models/comment.rb b/app/models/comment.rb index bcd1efca8..4ea7a1365 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -27,6 +27,7 @@ class Comment < ActiveRecord::Base #validates_presence_of :user # breaks during construction of new ones :( validates_inclusion_of :comment_type, :in => [ 'request' ] + validate :body_of_comment belongs_to :info_request has_many :info_request_events # in practice only ever has one @@ -52,16 +53,6 @@ class Comment < ActiveRecord::Base end end - # Check have edited comment - def validate - if self.body.empty? || self.body =~ /^\s+$/ - errors.add(:body, _("Please enter your annotation")) - end - if !MySociety::Validate.uses_mixed_capitals(self.body) - errors.add(:body, _('Please write your annotation using a mixture of capital and lower case letters. This makes it easier for others to read.')) - end - end - # Return body for display as HTML def get_body_for_html_display text = self.body.strip @@ -87,4 +78,15 @@ class Comment < ActiveRecord::Base yield(column.human_name, self.send(column.name), column.type.to_s, column.name) end end + + private + + def body_of_comment + if self.body.empty? || self.body =~ /^\s+$/ + errors.add(:body, _("Please enter your annotation")) + end + if !MySociety::Validate.uses_mixed_capitals(self.body) + errors.add(:body, _('Please write your annotation using a mixture of capital and lower case letters. This makes it easier for others to read.')) + end + end end |