29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/kaui/account_tags_controller.rb', line 29
def update
begin
current_tags = Kaui::KillbillHelper::get_tags_for_account(params[:account_id]).map { |tag| tag.tag_definition_id }
new_tags = []
params.each do |tag, tag_name|
tag_info = tag.split('_')
next if tag_info.size != 2 or tag_info[0] != 'tag'
new_tags << tag_info[1]
end
tags_to_remove = []
current_tags.each do |current_tag_definition_id|
tags_to_remove << current_tag_definition_id unless new_tags.include?(current_tag_definition_id)
end
tags_to_add = []
new_tags.each do |new_tag_definition_id|
tags_to_add << new_tag_definition_id unless current_tags.include?(new_tag_definition_id)
end
Kaui::KillbillHelper::remove_tags_for_account(params[:account_id], tags_to_remove) unless tags_to_remove.empty?
Kaui::KillbillHelper::add_tags_for_account(params[:account_id], tags_to_add) unless tags_to_add.empty?
rescue => e
flash[:error] = "Error while updating tags: #{as_string(e)}"
end
redirect_to kaui_engine.account_path(params[:account_id])
end
|