Skip to content

Instantly share code, notes, and snippets.

@johnnymo87
Created May 7, 2014 17:40
Show Gist options
  • Save johnnymo87/263e780a277a5e445db1 to your computer and use it in GitHub Desktop.
Save johnnymo87/263e780a277a5e445db1 to your computer and use it in GitHub Desktop.
Should I extract this private method into a service?
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
@johnnymo87
Copy link
Author

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 the User.invited_not_accepted collection into for parsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment