Permalink
Browse files

Extract Class Step Six

* Expose state from extracted class
* Assign only one instance variable for view
  • Loading branch information...
jferris committed Feb 14, 2013
1 parent 000babe commit a0505921b2cab9b233db0d0f9a3cec7a47c84edc
@@ -1,33 +1,25 @@
class InvitationsController < ApplicationController
def new
@survey = Survey.find(params[:survey_id])
@survey_inviter = SurveyInviter.new
@survey_inviter = SurveyInviter.new(survey: survey)
end

def create
@survey = Survey.find(params[:survey_id])
@survey_inviter = SurveyInviter.new(survey_inviter_attributes)
if @survey_inviter.valid?
@survey_inviter.deliver
redirect_to survey_path(@survey), notice: 'Invitation successfully sent'
redirect_to survey_path(survey), notice: 'Invitation successfully sent'
else
@recipients = recipients
@message = message
render 'new'
end
end

private

def survey_inviter_attributes
params[:invitation].merge(survey: @survey, sender: current_user)
params[:invitation].merge(survey: survey, sender: current_user)
end

def recipients
params[:invitation][:recipients]
end

def message
params[:invitation][:message]
def survey
Survey.find(params[:survey_id])
end
end
@@ -8,6 +8,8 @@ def initialize(attributes = {})
@sender = attributes[:sender]
end

attr_reader :message, :recipients, :survey

def valid?
valid_message? && valid_recipients?
end
@@ -1,9 +1,20 @@
<%= simple_form_for :invitation, url: survey_invitations_path(@survey) do |f| %>
<%= f.input :message, as: :text, input_html: { value: @message } %>
<%= simple_form_for(
:invitation,
url: survey_invitations_path(@survey_inviter.survey)
) do |f| %>
<%= f.input(
:message,
as: :text,
input_html: { value: @survey_inviter.message }
) %>
<% if @invlid_message %>
<div class="error">Please provide a message</div>
<% end %>
<%= f.input :recipients, as: :text, input_html: { value: @recipients } %>
<%= f.input(
:recipients,
as: :text,
input_html: { value: @survey_inviter.recipients }
) %>
<% if @survey_inviter.invalid_recipients %>
<div class="error">
Invalid email addresses:

0 comments on commit a050592

Please sign in to comment.