2013-01-01 22:45:35 +00:00
|
|
|
class Metacode < ActiveRecord::Base
|
|
|
|
|
2014-05-17 18:57:03 +00:00
|
|
|
has_many :in_metacode_sets
|
|
|
|
has_many :metacode_sets, :through => :in_metacode_sets
|
|
|
|
has_many :topics
|
2013-01-01 22:45:35 +00:00
|
|
|
|
2013-01-26 01:49:40 +00:00
|
|
|
def hasSelected(user)
|
|
|
|
return true if user.settings.metacodes.include? self.id.to_s
|
|
|
|
return false
|
|
|
|
end
|
2014-05-17 18:57:03 +00:00
|
|
|
|
|
|
|
def inMetacodeSet(metacode_set)
|
|
|
|
return true if self.metacode_sets.include? metacode_set
|
|
|
|
return false
|
|
|
|
end
|
2015-10-26 03:53:54 +00:00
|
|
|
|
|
|
|
def asset_path_icon
|
|
|
|
ActionController::Base.helpers.asset_path icon
|
|
|
|
end
|
|
|
|
|
|
|
|
#output json with asset_paths merged in
|
|
|
|
def as_json(options)
|
|
|
|
json = super(options.merge!(methods: :asset_path_icon))
|
2015-10-26 04:12:07 +00:00
|
|
|
json["icon"] = json["asset_path_icon"] if json["icon"].start_with?('http')
|
2015-10-26 03:53:54 +00:00
|
|
|
json.except("asset_path_icon")
|
|
|
|
end
|
2015-09-19 12:17:56 +00:00
|
|
|
end
|