2012-05-03 01:26:26 -04:00
|
|
|
class Link < ActiveRecord::Base
|
|
|
|
attr_accessible :description, :release, :url
|
2012-05-14 02:29:01 -04:00
|
|
|
validates :url, :presence => true#, :url => true
|
2012-05-03 01:26:26 -04:00
|
|
|
validates :description, :presence => true
|
|
|
|
|
2012-05-03 01:37:30 -04:00
|
|
|
def self.released
|
2012-05-03 01:26:26 -04:00
|
|
|
Link.where("DATE(release) <= DATE(?)", Time.now).order("release DESC")
|
|
|
|
end
|
|
|
|
|
2012-05-03 01:42:45 -04:00
|
|
|
def self.get_and_count(id = nil)
|
2012-05-03 01:26:26 -04:00
|
|
|
return false if nil
|
|
|
|
|
2012-05-03 01:42:45 -04:00
|
|
|
link = nil
|
2012-05-03 01:26:26 -04:00
|
|
|
Link.transaction do
|
|
|
|
link = Link.find(id)
|
2012-05-04 10:44:22 -04:00
|
|
|
#need to rate limit visits increment
|
|
|
|
link.increment!(:visits)
|
2012-05-03 01:26:26 -04:00
|
|
|
end
|
|
|
|
|
2012-05-04 23:41:46 -04:00
|
|
|
return false if link.release == nil
|
|
|
|
|
2012-05-03 01:26:26 -04:00
|
|
|
return link
|
|
|
|
end
|
|
|
|
end
|