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 11class InvitationsController < ApplicationController
22 def new
3- @survey = Survey . find ( params [ :survey_id ] )
4- @survey_inviter = SurveyInviter . new
3+ @survey_inviter = SurveyInviter . new ( survey : survey )
54 end
65
76 def create
8- @survey = Survey . find ( params [ :survey_id ] )
97 @survey_inviter = SurveyInviter . new ( survey_inviter_attributes )
108 if @survey_inviter . valid?
119 @survey_inviter . deliver
12- redirect_to survey_path ( @ survey) , notice : 'Invitation successfully sent'
10+ redirect_to survey_path ( survey ) , notice : 'Invitation successfully sent'
1311 else
14- @recipients = recipients
15- @message = message
1612 render 'new'
1713 end
1814 end
1915
2016 private
2117
2218 def survey_inviter_attributes
23- params [ :invitation ] . merge ( survey : @ survey, sender : current_user )
19+ params [ :invitation ] . merge ( survey : survey , sender : current_user )
2420 end
2521
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 ] )
3224 end
3325end
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ def initialize(attributes = {})
88 @sender = attributes [ :sender ]
99 end
1010
11+ attr_reader :message , :recipients , :survey
12+
1113 def valid?
1214 valid_message? && valid_recipients?
1315 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+ ) %>
310 <% if @invlid_message %>
411 <div class ="error "> Please provide a message</ div >
512 <% 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+ ) %>
718 <% if @survey_inviter . invalid_recipients %>
819 < div class ="error ">
920 Invalid email addresses:
You can’t perform that action at this time.
0 commit comments