diff options
author | rhenium <re4k@re4k.info> | 2013-06-05 05:20:25 +0900 |
---|---|---|
committer | rhenium <re4k@re4k.info> | 2013-06-05 05:20:25 +0900 |
commit | 10660a4699689220087f2dd0451b2ca2f6f0bafd (patch) | |
tree | 74f4735a5db5885e4a9cbcba8e0d949cce4f3c1f /app | |
parent | 2e6c8b1426e84ce45294545653dd4c2af3a82348 (diff) | |
download | aclog-10660a4699689220087f2dd0451b2ca2f6f0bafd.tar.gz |
fix models
Diffstat (limited to 'app')
-rw-r--r-- | app/models/account.rb | 7 | ||||
-rw-r--r-- | app/models/tweet.rb | 5 | ||||
-rw-r--r-- | app/models/user.rb | 1 |
3 files changed, 7 insertions, 6 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index ece02cd..ab8cd74 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -22,9 +22,10 @@ class Account < ActiveRecord::Base def active?; self.status == Account::ACTIVE end def update_settings!(params) - self.notification = params[:notification] - self.private = params[:private] + self.notification = !!params[:notification] + self.private = !!params[:private] self.save! if self.changed? + self end def deactivate! @@ -39,7 +40,7 @@ class Account < ActiveRecord::Base client = MessagePack::RPC::Client.new(transport, Rails.root.join("tmp", "sockets", "receiver.sock").to_s) if self.status == Account::ACTIVE client.call(:register, Marshal.dump(self)) - elsif self.status == Account::INACTIVE + elsif self.status == Account::DEACTIVATED client.call(:unregister, Marshal.dump(self)) end rescue Errno::ECONNREFUSED diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 5f0409f..4b09171 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -21,9 +21,8 @@ class Tweet < ActiveRecord::Base scope :order_by_retweets, -> { order("tweets.retweets_count DESC") } scope :order_by_reactions, -> { order("COALESCE(tweets.favorites_count, 0) + COALESCE(tweets.retweets_count, 0) DESC") } - scope :of, -> user { where(user: user) if user } - scope :favorited_by, -> user { joins(:favorites).where(favoriters: user) } - scope :retweeted_by, -> user { joins(:retweets).where(retweeters: user) } + scope :favorited_by, -> user { joins(:favorites).where(favorites: {user: user}) } + scope :retweeted_by, -> user { joins(:retweets).where(retweets: {user: user}) } scope :discovered_by, -> user { un = "SELECT favorites.tweet_id FROM favorites WHERE favorites.user_id = #{user.id}" + " UNION " + diff --git a/app/models/user.rb b/app/models/user.rb index 43696f8..a420946 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -110,3 +110,4 @@ class User < ActiveRecord::Base ret.map(&:flatten).sort_by {|user_id, favorites_count, retweets_count| -(favorites_count + retweets_count) } end end + |