Skip to content

Instantly share code, notes, and snippets.

@cheald
Created November 25, 2012 21:23
Show Gist options
  • Save cheald/4145433 to your computer and use it in GitHub Desktop.
Save cheald/4145433 to your computer and use it in GitHub Desktop.
class Question < ActiveRecord::Base
belongs_to :survey
def samples
populate_samples
end
private
def populate_samples
@samples ||= [].tap do |samples|
sample_count = samples.size
if sample_count < (self.survey.type == 'ABSurvey' ? 2 : 1)
if self.survey.type == 'ABSurvey'
if sample_count == 0
samples << Sample.new(:name => 'A')
end
samples << Sample.new(:name => 'B')
else
samples << Sample.new
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment