Skip to content

Commit

Permalink
completed_on filled when toggling completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Purcell committed Aug 18, 2010
1 parent ac6bb79 commit 4ba282f
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 76 deletions.
2 changes: 1 addition & 1 deletion app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def update
def complete
@list = List.find(params[:list_id])
@task = @list.tasks.find(params[:id])
@task.completed = !@task.completed
@task.toggle_completed
@task.save
respond_with( @task, :location => list_path(@list) )
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ class Task < ActiveRecord::Base
scope :completed, where(:completed => true)
scope :incomplete, where(:completed => false)
default_scope order(:position)

def toggle_completed
self.update_attributes(:completed => !self.completed,
:completed_on => Time.now)
end
end
15 changes: 1 addition & 14 deletions app/stylesheets/_standard.sass
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
/*
*
*Stuff and Nonsense Ltd.
*The Cow Shed Studio,
*Gwaenysgor,
*Flintshire, North Wales
*LL18 6EP, UK
*+44 1745 851848
*http://stuffandnonsense.co.uk
*http://forabeautifulweb.com
*http://transcendingcss.com
*http://twitter.com/malarkey
*
*SCREEN.CSS

=sans-family
:font-family Verdana, Helvetica, Arial, sans-serif

Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20100818184153_add_completed_on_to_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddCompletedOnToTasks < ActiveRecord::Migration
def self.up
add_column :tasks, :completed_on, :datetime
end

def self.down
remove_column :tasks, :completed_on, :datetime
end

end
5 changes: 3 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20100818153305) do
ActiveRecord::Schema.define(:version => 20100818184153) do

create_table "lists", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -38,12 +38,13 @@

create_table "tasks", :force => true do |t|
t.string "description"
t.boolean "completed", :default => false
t.boolean "completed", :default => false
t.integer "list_id"
t.datetime "created_at"
t.datetime "updated_at"
t.text "notes"
t.integer "position"
t.datetime "completed_on"
end

end
8 changes: 8 additions & 0 deletions lib/tasks/add_completed_on.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace :db do
task :fill_completed_on => :environment do
Task.completed.each do |t|
t.update_attributes(:completed_on => t.updated_at)
end
end
end

Loading

0 comments on commit 4ba282f

Please sign in to comment.