From bb998ba3fa6b6a69253ee3aeb018f09035d588a0 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 29 Mar 2012 21:48:34 +0200 Subject: [PATCH] fix #1265. The validations were not checked when making a project out of a todo. Thanks popsch for spotting this one! --- app/controllers/todos_controller.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 0219373e..79947c80 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -846,9 +846,16 @@ class TodosController < ApplicationController @todo = current_user.todos.find(params[:id]) @project = current_user.projects.new(:name => @todo.description, :description => @todo.notes, :default_context => @todo.context) - @todo.destroy - @project.save! - redirect_to project_url(@project) + + + unless @project.invalid? + @todo.destroy + @project.save! + redirect_to project_url(@project) + else + flash[:error] = "Could not create project from todo: #{@project.errors.full_messages[0]}" + redirect_to request.env["HTTP_REFERER"] || root_url + end end def show_notes