Created
May 7, 2014 17:40
-
-
Save johnnymo87/263e780a277a5e445db1 to your computer and use it in GitHub Desktop.
Should I extract this private method into a service?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserReportsController < ApplicationController | |
layout 'full_width', :except => [:invited] | |
... | |
def invited | |
@resend_invitation = true | |
@invitations = serialize_invitations | |
render :template => 'user_reports/invited', :layout => 'invitation_table' | |
end | |
... | |
private | |
def serialize_invitations | |
User.invited_not_accepted.select do |user| | |
user.organization.present? # because invitation data may be 'dirty' | |
end.map do |user| | |
{ | |
id: user.organization.id, | |
name: user.organization.name, | |
email: user.email, | |
date: user.invitation_sent_at | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The point of this private method is to prepare a custom hash of values for a custom table in the one view that this controller action is for. I don't expect that I'll ever have to extend this private method to return different kinds of hashes, so making a service to handle this logic seems like overkill.
The alternative would be to have an
InvitationSerializer
service that I would inject theUser.invited_not_accepted
collection into for parsing.