diff --git a/app/models/category.rb b/app/models/category.rb index ca3e7c9..437b1a2 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -43,7 +43,7 @@ class Category < ActiveRecord::Base scope :nospecial, -> { where.not(name: 'Special') } scope :newest, -> { includes(:articles).order("articles.created_at DESC") } # scope :page, lambda { |page| {:limit => "#{(page-1)*PER_PAGE}, #{(page-1)*PER_PAGE+PER_PAGE}"} } - scope :of_user, -> (user) { where("articles.user_id", user.id).includes(:articles) } + scope :of_user, -> (user) { where(articles: {user: user}).includes(:articles) } has_many :articles, -> { order("created_at DESC") } has_many :issues, -> { order("created_at DESC") } diff --git a/app/models/contest.rb b/app/models/contest.rb index cc5e9ef..513a1ec 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -40,8 +40,6 @@ class Contest < ActiveRecord::Base TYPE_LEAGUE = 1 TYPE_BRACKET = 2 - #attr_protected :id, :updated_at, :created_at - scope :active, -> { where.not(status: STATUS_CLOSED) } scope :inactive, -> { where(status: STATUS_CLOSED) } scope :joinable, -> { where(status: STATUS_OPEN) } @@ -57,7 +55,7 @@ class Contest < ActiveRecord::Base has_many :predictions, :through => :matches has_many :brackets has_many :preds_with_score, -> { - select("predictions.id, predictions.user_id + select("predictions.id, predictions.user_id, SUM(result) AS correct, SUM(result)/COUNT(*)*100 AS score, COUNT(*) AS total") diff --git a/app/models/match.rb b/app/models/match.rb index 0514cdf..ebb6a6d 100755 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -88,9 +88,9 @@ class Match < ActiveRecord::Base scope :on_day, -> (day) { where("match_time > ? and match_time < ?", day.beginning_of_day, day.end_of_day) } scope :on_week, -> (time) { where("match_time > ? and match_time < ?", time.beginning_of_week, time.end_of_week) } scope :of_contester, -> (contester) { where("contester1_id = ? OR contester2_id = ?", contester.id, contester.id) } - scope :of_user, -> (user) { includes(:matchers).where("matchers.user_id = ?", user.id) } + scope :of_user, -> (user) { includes(:matchers).where(matchers: {user_id: user.id}) } scope :of_team, -> (team) { includes({:contester1 => :team, :contester2 => :team}).where("teams.id = ? OR teams_contesters.id = ?", team.id, team.id) } - scope :of_userteam, -> (user, team) { eager_load({:matchers => {:contester => :team}}).where("teams.id = ? AND matchers.user_id = ?", team.id, user.id) } + scope :of_userteam, -> (user, team) { includes({:matchers => {:contester => :team}}).where(teams: {id: team.id}, matchers: {user_id: user.id}) } scope :within_time, -> (from, to) { where("match_time > ? AND match_time < ?", from.utc, to.utc) } scope :around, -> (time) { where("match_time > ? AND match_time < ?", time.ago(MATCH_LENGTH).utc, time.ago(-MATCH_LENGTH).utc) } scope :after, -> (time) { where("match_time > ? AND match_time < ?", time.utc, time.ago(-MATCH_LENGTH).utc) } diff --git a/app/models/prediction.rb b/app/models/prediction.rb index 7a2ec0d..88b29a7 100644 --- a/app/models/prediction.rb +++ b/app/models/prediction.rb @@ -27,7 +27,7 @@ class Prediction < ActiveRecord::Base validates_inclusion_of :score2, :in => 0..99, :message => "Invalid score" validates_uniqueness_of :match_id, :scope => :user_id - scope :with_contest, -> { include({:match => :contest}) } + scope :with_contest, -> { includes({:match => :contest}) } belongs_to :match belongs_to :user diff --git a/app/models/teamer.rb b/app/models/teamer.rb index 90068e6..c72ff88 100644 --- a/app/models/teamer.rb +++ b/app/models/teamer.rb @@ -41,7 +41,7 @@ class Teamer < ActiveRecord::Base scope :active, -> { where("teamers.rank >= ?", RANK_MEMBER) } scope :leaders, -> { where("teamers.rank >= ?", RANK_DEPUTEE) } scope :of_team, -> (team) { where("teamers.team_id" => team.id) } - scope :active_teams, -> { includes(:team).where("teams.active = ?", true) } + scope :active_teams, -> { includes(:team).where(teams: {active: true}) } scope :unique_by_team, -> { group("user_id, team_id") } scope :ordered, -> { order("rank DESC, created_at ASC") } scope :historic, -> (user, time) { diff --git a/app/models/topic.rb b/app/models/topic.rb index 1345d36..8a28927 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -109,7 +109,7 @@ class Topic < ActiveRecord::Base return false unless cuser errors.add :bans, I18n.t(:bans_mute) if cuser.banned?(Ban::TYPE_MUTE) and forum != Forum::BANS errors.add :bans, I18n.t(:registered_for_week) unless cuser.verified? - (Forum.available_to(cuser, Forumer::ACCESS_TOPIC).of_forum(forum).first and errors.size == 0) + Forum.available_to(cuser, Forumer::ACCESS_TOPIC).where(id: forum_id) and errors.size == 0 end def can_update? cuser @@ -129,6 +129,6 @@ class Topic < ActiveRecord::Base end def self.params(params, cuser) - params.permit(:state, :title, :forum_id, :user_id) + params.require(:topic).permit(:state, :title, :forum_id, :user_id, :first_post) end end