Commit a5b5066efab7d7c62093b3b346b002b8d48b497d

Authored by Michel Felipe
1 parent ce1c8afe

Store task tags on database using acts_as_taggable gem

app/controllers/my_profile/tasks_controller.rb
1 1 class TasksController < MyProfileController
2 2  
3 3 protect 'perform_task', :profile
4   -
  4 +
5 5 def index
6 6 @filter = params[:filter_type].blank? ? nil : params[:filter_type]
7 7 @task_types = Task.pending_types_for(profile)
... ... @@ -17,18 +17,33 @@ class TasksController &lt; MyProfileController
17 17  
18 18 def close
19 19 failed = {}
  20 + save = false
20 21  
21 22 if params[:tasks]
22 23 params[:tasks].each do |id, value|
23 24 decision = value[:decision]
24   - if request.post? && VALID_DECISIONS.include?(decision) && id && decision != 'skip'
  25 +
  26 + if value[:task].is_a?(Hash) && value[:task][:tag_list]
  27 +
25 28 task = profile.find_in_all_tasks(id)
26   - begin
27   - task.update_attributes(value[:task])
28   - task.send(decision)
29   - rescue Exception => ex
30   - message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})"
31   - failed[ex.message] ? failed[ex.message] << message : failed[ex.message] = [message]
  29 + task.tag_list = value[:task][:tag_list]
  30 + value[:task].delete('tag_list')
  31 +
  32 + save = true
  33 + end
  34 +
  35 + if request.post?
  36 + if VALID_DECISIONS.include?(decision) && id && decision != 'skip'
  37 + task ||= profile.find_in_all_tasks(id)
  38 + begin
  39 + task.update_attributes(value[:task])
  40 + task.send(decision)
  41 + rescue Exception => ex
  42 + message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})"
  43 + failed[ex.message] ? failed[ex.message] << message : failed[ex.message] = [message]
  44 + end
  45 + elsif save
  46 + task.save!
32 47 end
33 48 end
34 49 end
... ...
app/models/task.rb
... ... @@ -12,6 +12,7 @@
12 12 class Task < ActiveRecord::Base
13 13  
14 14 acts_as_having_settings :field => :data
  15 + acts_as_ordered_taggable
15 16  
16 17 module Status
17 18 # the status of tasks just created
... ...