Skip to content

Instantly share code, notes, and snippets.

@shuma
Created January 21, 2013 00:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save shuma/4582873 to your computer and use it in GitHub Desktop.
class School < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: [:slugged, :history]
has_many :reviews
has_many :prices
# sunspot search
searchable do
text :name, :locality
end
# Beräknar medelvärdet för alla recensioner
def avgerage_review_rating
return nil if reviews.blank?
reviews.average(:rating)
end
def count_checkins(name)
u = @current_user
u.@facebook.fql_query("SELECT checkins FROM page WHERE name = #{name}")
end
# Beräknar antal recensioner
def count_reviews
reviews.count
end
def sum
prices.min + prices.littin + prices.risk1 + prices.risk2 + prices.hyrbil + 1550
end
def facebook
@facebook ||= Koala::Facebook::API.new(oauth_token)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment