2013-01-01 17:45:35 -05:00
|
|
|
class Metacode < ActiveRecord::Base
|
2014-05-17 14:57:03 -04:00
|
|
|
has_many :in_metacode_sets
|
|
|
|
has_many :metacode_sets, :through => :in_metacode_sets
|
|
|
|
has_many :topics
|
2013-01-01 17:45:35 -05:00
|
|
|
|
2016-02-23 14:58:20 +08:00
|
|
|
# This method associates the attribute ":icon" with a file attachment
|
|
|
|
has_attached_file :icon, :styles => {
|
|
|
|
:ninetysix => ['96x96#', :png],
|
|
|
|
},
|
|
|
|
:default_url => 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png'
|
|
|
|
|
|
|
|
# Validate the attached icon is image/jpg, image/png, etc
|
|
|
|
validates_attachment_content_type :icon, :content_type => /\Aimage\/.*\Z/
|
|
|
|
|
2013-01-25 20:49:40 -05:00
|
|
|
def hasSelected(user)
|
|
|
|
return true if user.settings.metacodes.include? self.id.to_s
|
|
|
|
return false
|
|
|
|
end
|
2014-05-17 14:57:03 -04:00
|
|
|
|
|
|
|
def inMetacodeSet(metacode_set)
|
|
|
|
return true if self.metacode_sets.include? metacode_set
|
|
|
|
return false
|
|
|
|
end
|
2015-09-19 20:17:56 +08:00
|
|
|
end
|