Permalink
Browse files

added composite primary key gem because Autofinger model had no prima…

…ry key. Autofinger list is now kept up to date as one reads a plan
  • Loading branch information...
1 parent ba8f2d1 commit 34ca3460b22ef1e375d5f6b1a680d5eaa53780e0 @annaswims annaswims committed Aug 11, 2011
Showing with 14 additions and 7 deletions.
  1. +3 −0 Gemfile
  2. +3 −0 Gemfile.lock
  3. +2 −4 app/controllers/plans_controller.rb
  4. +6 −3 app/models/autofinger.rb
View
@@ -33,6 +33,9 @@ gem 'jquery-rails', '>= 0.2.6'
# https://github.com/mislav/will_paginate/tree/rails3
gem 'will_paginate', '~> 3.0.beta'
+# supports composite primary keys for legacy tables like Autfinger https://github.com/drnic/composite_primary_keys
+gem "composite_primary_keys", "~> 3.1.10"
+
group :production do
#email any errors to people specified in the environment.rb
gem "exception_notification", :git => "git://github.com/rails/exception_notification", :require => 'exception_notifier'
View
@@ -48,6 +48,8 @@ GEM
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
columnize (0.3.2)
+ composite_primary_keys (3.1.10)
+ activerecord (~> 3.0.0, >= 3.0.5)
crypt3 (1.1.2)
diff-lcs (1.1.2)
dynamic_form (1.1.4)
@@ -142,6 +144,7 @@ DEPENDENCIES
annotate
authlogic (~> 3.0.0)
capistrano
+ composite_primary_keys (~> 3.1.10)
crypt3
dynamic_form
exception_notification!
@@ -26,7 +26,7 @@ def show
def mark_level_as_read
Autofinger.mark_level_as_read(current_account.userid, params[:level])
- redirect_to params[:return_to]
+ redirect_to params[:return_to]
end
def set_autofinger_level
@@ -36,7 +36,6 @@ def set_autofinger_level
def search
@account = Account.find_by_username(params[:id])
- debugger
if !@account.blank?
redirect_to read_plan_path( :id => @account.username )
else
@@ -45,8 +44,7 @@ def search
end
def load_autofingers
- @autofingers = Autofinger.where(:owner=>@current_account.userid, :priority=> session[:autofinger_level])
- #TODO unread only
+ @autofingers = Autofinger.where(:owner=>@current_account.userid, :priority=> session[:autofinger_level], :updated => "1")
end
View
@@ -1,17 +1,20 @@
+require 'composite_primary_keys'
class Autofinger < ActiveRecord::Base
+ set_primary_keys :owner, :interest
set_table_name :autofinger
validates_presence_of :owner, :interest, :priority
belongs_to :interested_party, :foreign_key => :owner, :class_name => "Account"
belongs_to :subject_of_interest, :foreign_key => :interest, :class_name => "Account"
+
validates_presence_of :interest, :owner
def self.mark_plan_as_read(owner, interest)
- autofinger = Autofinger.where(:owner=>owner, :interest=> interest ).first
+ autofinger = Autofinger.where(:owner=> owner, :interest=> interest ).first
unless autofinger.blank?
- autofinger.updated = '0'
+ autofinger.updated = "0"
autofinger.readtime = Time.now
- # autofinger.save
+ autofinger.save
end
end

0 comments on commit 34ca346

Please sign in to comment.