File tree Expand file tree Collapse file tree 3 files changed +21
-16
lines changed Expand file tree Collapse file tree 3 files changed +21
-16
lines changed Original file line number Diff line number Diff line change 1
1
class InvitationsController < ApplicationController
2
2
def new
3
- @survey = Survey . find ( params [ :survey_id ] )
4
- @survey_inviter = SurveyInviter . new
3
+ @survey_inviter = SurveyInviter . new ( survey : survey )
5
4
end
6
5
7
6
def create
8
- @survey = Survey . find ( params [ :survey_id ] )
9
7
@survey_inviter = SurveyInviter . new ( survey_inviter_attributes )
10
8
if @survey_inviter . valid?
11
9
@survey_inviter . deliver
12
- redirect_to survey_path ( @ survey) , notice : 'Invitation successfully sent'
10
+ redirect_to survey_path ( survey ) , notice : 'Invitation successfully sent'
13
11
else
14
- @recipients = recipients
15
- @message = message
16
12
render 'new'
17
13
end
18
14
end
19
15
20
16
private
21
17
22
18
def survey_inviter_attributes
23
- params [ :invitation ] . merge ( survey : @ survey, sender : current_user )
19
+ params [ :invitation ] . merge ( survey : survey , sender : current_user )
24
20
end
25
21
26
- def recipients
27
- params [ :invitation ] [ :recipients ]
28
- end
29
-
30
- def message
31
- params [ :invitation ] [ :message ]
22
+ def survey
23
+ Survey . find ( params [ :survey_id ] )
32
24
end
33
25
end
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ def initialize(attributes = {})
8
8
@sender = attributes [ :sender ]
9
9
end
10
10
11
+ attr_reader :message , :recipients , :survey
12
+
11
13
def valid?
12
14
valid_message? && valid_recipients?
13
15
end
Original file line number Diff line number Diff line change 1
- <%= simple_form_for :invitation, url: survey_invitations_path(@survey) do |f| %>
2
- <%= f.input :message, as: :text, input_html: { value: @message } %>
1
+ <%= simple_form_for(
2
+ :invitation,
3
+ url: survey_invitations_path(@survey_inviter.survey)
4
+ ) do |f| %>
5
+ <%= f.input(
6
+ :message,
7
+ as: :text,
8
+ input_html: { value: @survey_inviter.message }
9
+ ) %>
3
10
<% if @invlid_message %>
4
11
<div class ="error "> Please provide a message</ div >
5
12
<% end %>
6
- <%= f . input :recipients , as : :text , input_html : { value : @recipients } %>
13
+ <%= f . input (
14
+ :recipients ,
15
+ as : :text ,
16
+ input_html : { value : @survey_inviter . recipients }
17
+ ) %>
7
18
<% if @survey_inviter . invalid_recipients %>
8
19
< div class ="error ">
9
20
Invalid email addresses:
You can’t perform that action at this time.
0 commit comments