From 37a45313a0c0876272a871093e112c159c34b547 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Tue, 4 Aug 2009 13:54:19 +0200 Subject: [PATCH] fixes #929 where editing a newly added todo on the tag view would cause an error because tag_name was not passed around --- app/controllers/todos_controller.rb | 20 +++++++++++++------- app/helpers/todos_helper.rb | 2 +- app/views/shared/_add_new_item_form.rhtml | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 2784be62..c472d40e 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -50,6 +50,7 @@ class TodosController < ApplicationController def create @source_view = params['_source_view'] || 'todo' + @tag_name = params['_tag_name'] p = TodoCreateParamsHelper.new(params, prefs) p.parse_dates() unless mobile? tag_list = p.tag_list @@ -506,9 +507,9 @@ class TodosController < ApplicationController def auto_complete_for_tag @items = Tag.find(:all, - :conditions => [ "name LIKE ?", '%' + params['tag_list'] + '%' ], - :order => "name ASC", - :limit => 10) + :conditions => [ "name LIKE ?", '%' + params['tag_list'] + '%' ], + :order => "name ASC", + :limit => 10) render :inline => "<%= auto_complete_result(@items, :name) %>" end @@ -718,10 +719,15 @@ class TodosController < ApplicationController end def determine_deferred_tag_count(tag) - tag_collection = Tag.find_by_name(tag).todos - @deferred_tag_count = tag_collection.count(:all, - :conditions => ['todos.user_id = ? and state = ?', current_user.id, 'deferred'], - :order => 'show_from ASC, todos.created_at DESC') + tags = Tag.find_by_name(tag) + if tags.nil? + # should normally not happen, but is a workaround for #929 + @deferred_tag_count = 0 + else + @deferred_tag_count = tags.todos.count(:all, + :conditions => ['todos.user_id = ? and state = ?', current_user.id, 'deferred'], + :order => 'show_from ASC, todos.created_at DESC') + end end def render_todos_html diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 9b886679..f11b5fbe 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -229,7 +229,7 @@ module TodosHelper def should_show_new_item - if @todo.project.nil? == false + unless @todo.project.nil? # do not show new actions that were added to hidden or completed projects # on home page and context page return false if source_view_is(:todo) && (@todo.project.hidden? || @todo.project.completed?) diff --git a/app/views/shared/_add_new_item_form.rhtml b/app/views/shared/_add_new_item_form.rhtml index a31136c5..66458200 100644 --- a/app/views/shared/_add_new_item_form.rhtml +++ b/app/views/shared/_add_new_item_form.rhtml @@ -62,6 +62,7 @@ <%= source_view_tag( @source_view ) %> + <%= hidden_field_tag :_tag_name, @tag_name.underscore.gsub(/\s+/,'_') if source_view_is :tag %>