This repository has been archived on 2020-05-27. You can view files and clone it, but cannot push or open issues/pull-requests.
2008-06-27 00:13:15 -04:00
|
|
|
class Comment < ActiveRecord::Base
|
|
|
|
belongs_to :page
|
|
|
|
belongs_to :author
|
2008-08-07 18:45:33 -04:00
|
|
|
validate :safe_url
|
2008-06-27 00:13:15 -04:00
|
|
|
|
|
|
|
def name
|
|
|
|
if self.author
|
|
|
|
self.author.name
|
|
|
|
else
|
|
|
|
self.user
|
|
|
|
end
|
|
|
|
end
|
2008-08-07 18:45:33 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def safe_url
|
|
|
|
return true if self.url.to_s.empty?
|
|
|
|
if self.url =~ /^http:\/\// and self.url !~ /[^a-zA-Z0-9\._:\-\/]/
|
|
|
|
true
|
|
|
|
else
|
|
|
|
self.errors.add(:url, "is not a permissible address")
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2008-06-27 00:13:15 -04:00
|
|
|
end
|