Last active
December 29, 2015 03:09
Revisions
-
Jragon renamed this gist
Nov 22, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Jragon revised this gist
Nov 22, 2013 . 6 changed files with 60 additions and 55 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,45 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ class Change < ActiveRecord::Base has_many :conversations validates :name, presence: true # def self.top # with_rank.order("rank desc").limit(1) # end # def self.with_rank # joins(:conversations).select("changes.*, SUM(conversations.rank) as rank") # end def self.top_ranked(load_conversation=true) with_rank(load_conversation).order("rank desc").limit(1) end def self.with_rank(load_conversation=true) q = select("changes.*, SUM(conversations.rank) as rank") q = q.joins(:conversations) if load_conversation return q end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ class Conversation < ActiveRecord::Base belongs_to :discussion belongs_to :change validates :discussion_id, :change_id, :rank, :ten_seed, presence: true validates :change_id, :rank, uniqueness: { scope: :dicussion_id } end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ class Discussion < ActiveRecord::Base belongs_to :village belongs_to :group has_many :conversations validates :lead_facilitator, :duration, :date_held, :group_id, :village_id, presence: true end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,15 @@ 2.0.0-p247 :004 > Change.all.each { |c| c.with_rank.rank } Change Load (0.6ms) SELECT "changes".* FROM "changes" NoMethodError: undefined method `with_rank' for #<Change:0x00000004272050> from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:436:in `method_missing' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:131:in `method_missing' from (irb):4:in `block in irb_binding' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:13:in `each' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:13:in `each' from (irb):4 from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>' 2.0.0-p247 :005 > This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ class Village < ActiveRecord::Base belongs_to :programme has_many :discussions has_many :conversations, through: :discussions has_many :changes, through: :conversations validates :name, :programme_id, presence: true def top_change changes.merge Change.top_ranked end end -
Jragon revised this gist
Nov 22, 2013 . 1 changed file with 11 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,13 @@ 2.0.0-p247 :002 > Conversation.all Conversation Load (0.8ms) SELECT "conversations".* FROM "conversations" => #<ActiveRecord::Relation [ #<Conversation id: 1, discussion_id: 1, change_id: 2, rank: 1, ten_seed: 10, observations: "It helped\nA lot", created_at: "2013-11-21 19:28:09", updated_at: "2013-11-21 19:28:09">, #<Conversation id: 2, discussion_id: 1, change_id: 1, rank: 2, ten_seed: 8, observations: "It helped quite a bit", created_at: "2013-11-21 19:29:56", updated_at: "2013-11-21 19:29:56">, #<Conversation id: 3, discussion_id: 1, change_id: 4, rank: 3, ten_seed: 8, observations: "Wasn't the best", created_at: "2013-11-21 19:30:17", updated_at: "2013-11-21 21:34:51">]> 2.0.0-p247 :003 > Change.all Change Load (0.3ms) SELECT "changes".* FROM "changes" => #<ActiveRecord::Relation [ #<Change id: 1, name: "Health", created_at: "2013-11-21 19:19:44", updated_at: "2013-11-21 19:19:44">, #<Change id: 2, name: "School", created_at: "2013-11-21 19:19:49", updated_at: "2013-11-21 19:19:49">, #<Change id: 4, name: "Boarhole", created_at: "2013-11-21 19:20:28", updated_at: "2013-11-21 19:20:28">]> -
Jragon revised this gist
Nov 22, 2013 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ 2.0.0-p247 :002 > Conversation.all Conversation Load (0.8ms) SELECT "conversations".* FROM "conversations" => #<ActiveRecord::Relation [#<Conversation id: 1, discussion_id: 1, change_id: 2, rank: 1, ten_seed: 10, observations: "It helped\nA lot", created_at: "2013-11-21 19:28:09", updated_at: "2013-11-21 19:28:09">, #<Conversation id: 2, discussion_id: 1, change_id: 1, rank: 2, ten_seed: 8, observations: "It helped quite a bit", created_at: "2013-11-21 19:29:56", updated_at: "2013-11-21 19:29:56">, #<Conversation id: 3, discussion_id: 1, change_id: 4, rank: 3, ten_seed: 8, observations: "Wasn't the best", created_at: "2013-11-21 19:30:17", updated_at: "2013-11-21 21:34:51">]> 2.0.0-p247 :003 > -
Jragon revised this gist
Nov 22, 2013 . 2 changed files with 3 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ 2.0.0-p247 :004 > Village.first.top_change.to_sql Village Load (0.7ms) SELECT "villages".* FROM "villages" ORDER BY "villages"."id" ASC LIMIT 1 => "SELECT changes.*, SUM(conversations.rank) as rank FROM \"changes\" INNER JOIN \"conversations\" \"conversations_changes\" ON \"conversations_changes\".\"change_id\" = \"changes\".\"id\" INNER JOIN \"conversations\" ON \"changes\".\"id\" = \"conversations\".\"change_id\" INNER JOIN \"discussions\" ON \"conversations\".\"discussion_id\" = \"discussions\".\"id\" WHERE \"discussions\".\"village_id\" = ? ORDER BY rank desc LIMIT 1" -
Jragon revised this gist
Nov 22, 2013 . No changes.There are no files selected for viewing
-
Jragon revised this gist
Nov 22, 2013 . 1 changed file with 7 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,15 @@ 2.0.0-p247 :001 > Village.first.top_change Village Load (0.2ms) SELECT "villages".* FROM "villages" ORDER BY "villages"."id" ASC LIMIT 1 (0.2ms) SELECT MAX(rank) AS max_id FROM "changes" INNER JOIN "conversations" ON "conversations"."change_id" = "changes"."id" NoMethodError: undefined method `default_scoped?' for 3:Fixnum from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/relation/merger.rb:45:in `initialize' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/relation/spawn_methods.rb:44:in `new' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/relation/spawn_methods.rb:44:in `merge!' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/relation/spawn_methods.rb:33:in `merge' from /home/jragon/Code/Rails/OTIS/app/models/village.rb:10:in `top_change' from (irb):1 from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>' -
Jragon revised this gist
Nov 22, 2013 . 1 changed file with 45 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ class Village < ActiveRecord::Base belongs_to :programme has_many :discussions has_many :conversations, through: :discussions has_many :changes, through: :conversations validates :name, :programme_id, presence: true def top_change changes & Change.top end end class Change < ActiveRecord::Base has_many :conversations validates :name, presence: true def self.top with_rank.maximum("rank") end def self.with_rank joins(:conversations).select("changes.*, SUM(conversations.rank) as rank") end end class Conversation < ActiveRecord::Base belongs_to :discussion belongs_to :change validates :discussion_id, :change_id, :rank, :ten_seed, presence: true validates :change_id, :rank, uniqueness: { scope: :dicussion_id } end class Discussion < ActiveRecord::Base belongs_to :village belongs_to :group has_many :conversations validates :lead_facilitator, :duration, :date_held, :group_id, :village_id, presence: true end -
Jragon created this gist
Nov 22, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ 2.0.0-p247 :001 > Village.first.top_change Village Load (0.3ms) SELECT "villages".* FROM "villages" ORDER BY "villages"."id" ASC LIMIT 1 (0.3ms) SELECT MAX(rank) AS max_id FROM "changes" INNER JOIN "conversations" ON "conversations"."change_id" = "changes"."id" Change Load (2.3ms) SELECT "changes".* FROM "changes" INNER JOIN "conversations" ON "changes"."id" = "conversations"."change_id" INNER JOIN "discussions" ON "conversations"."discussion_id" = "discussions"."id" WHERE "discussions"."village_id" = ? [["village_id", 1]] TypeError: no implicit conversion of Fixnum into Array from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:63:in `&' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:63:in `method_missing' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-deprecated_finders-1.0.3/lib/active_record/deprecated_finders/collection_proxy.rb:22:in `method_missing' from /home/jragon/Code/Rails/OTIS/app/models/village.rb:10:in `top_change' from (irb):1 from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start' from /home/jragon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>' 2.0.0-p247 :002 >