Created
October 1, 2015 07:43
-
-
Save certainty/78e23bf9c896baf7e576 to your computer and use it in GitHub Desktop.
first iteration
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
def create | |
if CreateCampaignAccessCodeGroup.(@campaign) | |
redirect_to campaign_access_code_groups_path, notice: _("Group and codes were successfully created.") | |
else | |
render :new | |
end | |
end |
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 CreateCampaignAccessCodeGroup | |
class << self | |
def call(campaign) | |
new(campaign).call | |
end | |
end | |
def initialize(campaign) | |
@campaign = campaign | |
@access_code_group = create_group(campaign) | |
end | |
def call | |
@access_code_group.save && create_access_groups | |
end | |
private | |
def create_group(campaign) | |
# .... | |
end | |
def create_access_groups | |
@access_code_group.count.times(&method(:create_access_group)) | |
end | |
def create_access_group | |
begin | |
CampaignAccessCode.create( | |
campaign: @campaign, | |
campaign_access_code_group: @access_code_group, | |
code: CampaignAccessCode.generate(@access_code_group.initials) | |
) | |
rescue ActiveRecord::RecordInvalid => e | |
puts e | |
end | |
true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment