Skip to content

Instantly share code, notes, and snippets.

@harlow
Last active December 17, 2015 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harlow/5674081 to your computer and use it in GitHub Desktop.
Save harlow/5674081 to your computer and use it in GitHub Desktop.
class TaskCompletion
include ActiveModel::Model
attr_accessor :task, :complete
validates :complete, inclusion: { in: [true, false] }
def self.for_task(task, params={})
new(params).tap do |completion|
completion.task = task
end
end
def save
return true if task.complete?
if valid?
completion_detail.update_attributes({
some_var: 'OK'
})
task.update_attributes(complete: complete)
else
@errors = completion_detail.errors
false
end
end
def valid?
completion_detail.valid?
end
private
def completion_detail
task.completion_detail
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment