mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-07 01:38:50 +01:00
Move Project#create_from_todo to its own class
The point of this is to keep as many things out of the ActiveRecord objects as possible and use them as just a thin database abstraction layer.
This commit is contained in:
parent
18883c6ecc
commit
883ea2b968
5 changed files with 50 additions and 24 deletions
|
|
@ -776,7 +776,7 @@ class TodosController < ApplicationController
|
|||
|
||||
def convert_to_project
|
||||
todo = current_user.todos.find(params[:id])
|
||||
@project = Project.create_from_todo(todo)
|
||||
@project = ProjectFromTodo.new(todo).create
|
||||
|
||||
if @project.valid?
|
||||
redirect_to project_url(@project)
|
||||
|
|
|
|||
|
|
@ -47,21 +47,6 @@ class Project < ActiveRecord::Base
|
|||
NullProject.new
|
||||
end
|
||||
|
||||
def self.create_from_todo(todo)
|
||||
project = Project.new(:name => todo.description,
|
||||
:description => todo.notes,
|
||||
:default_context => todo.context)
|
||||
|
||||
project.user = todo.user
|
||||
|
||||
if project.valid?
|
||||
todo.destroy
|
||||
project.save!
|
||||
end
|
||||
|
||||
project
|
||||
end
|
||||
|
||||
def hide_todos
|
||||
todos.each do |t|
|
||||
unless t.completed? || t.deferred?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue