10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/admin/group_invitations_controller.rb', line 10
def create
if params[:invite_reader] || params[:import_reader]
notice = []
if invites = params[:invite_reader]
invite_counter = 0
invites.each do |i|
if reader = Reader.find_by_id(i)
reader.groups << @group unless reader.is_in?(@group)
@group.send_welcome_to(reader)
invite_counter += 1
end
end
notice << "#{invite_counter} existing"
end
if imports = params[:import_reader]
import_counter = 0
imports.each do |i|
r = params["reader_#{i}".to_sym]
reader = Reader.new(r)
reader.create_password!
if reader.save!
reader.groups << @group
reader.send_group_invitation_message(@group)
import_counter += 1
end
notice << "#{import_counter} new"
end
end
flash[:notice] = notice.join(' and ') + " readers invited into the #{@group.name} group"
redirect_to admin_group_url(@group)
else
if params[:readerlist] && @readers = readers_from_csv(params[:readerlist])
render :action => 'preview'
else
render :action => 'new'
end
end
end
|