10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/generators/atrium/install/templates/controllers/selected_items_controller.rb', line 10
def save
success = true
existing_selected_items = current_user.selected_document_ids
@selected_items = params[:items] || []
@selected_items.delete_if {|key, value| existing_selected_items.include?(value[:document_id]) }
@selected_items.each do |key, item|
success = false unless current_user.selected_items.create(item)
end
if @selected_items.length > 0 && success
flash[:notice] = 'Selected items '+ @selected_items.length.to_s + ' was saved successfully.'
elsif @selected_items.length > 0
flash[:error] = 'Error saving selected items'
end
redirect_to :back
end
|