File tree Expand file tree Collapse file tree 1 file changed +34
-15
lines changed
example_app/app/controllers Expand file tree Collapse file tree 1 file changed +34
-15
lines changed Original file line number Diff line number Diff line change @@ -7,32 +7,51 @@ def new
77
88 def create
99 @survey = Survey . find ( params [ :survey_id ] )
10-
11- @recipients = params [ :invitation ] [ :recipients ]
12- recipient_list = @recipients . gsub ( /\s +/ , '' ) . split ( /[\n ,;]+/ )
13-
14- @invalid_recipients = recipient_list . map do |item |
15- unless item . match ( EMAIL_REGEX )
16- item
17- end
18- end . compact
19-
20- @message = params [ :invitation ] [ :message ]
21-
22- if @invalid_recipients . empty? && @message . present?
10+ if valid_recipients? && valid_message?
2311 recipient_list . each do |email |
2412 invitation = Invitation . create (
2513 survey : @survey ,
2614 sender : current_user ,
2715 recipient_email : email ,
2816 status : 'pending'
2917 )
30- Mailer . invitation_notification ( invitation , @ message)
18+ Mailer . invitation_notification ( invitation , message )
3119 end
32-
3320 redirect_to survey_path ( @survey ) , notice : 'Invitation successfully sent'
3421 else
22+ @recipients = recipients
23+ @message = message
3524 render 'new'
3625 end
3726 end
27+
28+ private
29+
30+ def valid_recipients?
31+ invalid_recipients . empty?
32+ end
33+
34+ def valid_message?
35+ message . present?
36+ end
37+
38+ def invalid_recipients
39+ @invalid_recipients ||= recipient_list . map do |item |
40+ unless item . match ( EMAIL_REGEX )
41+ item
42+ end
43+ end . compact
44+ end
45+
46+ def recipient_list
47+ @recipient_list ||= recipients . gsub ( /\s +/ , '' ) . split ( /[\n ,;]+/ )
48+ end
49+
50+ def recipients
51+ params [ :invitation ] [ :recipients ]
52+ end
53+
54+ def message
55+ params [ :invitation ] [ :message ]
56+ end
3857end
You can’t perform that action at this time.
0 commit comments