Skip to content

Instantly share code, notes, and snippets.

@sharipov-ru
Created April 5, 2013 12:33
Show Gist options
  • Save sharipov-ru/5318967 to your computer and use it in GitHub Desktop.
Save sharipov-ru/5318967 to your computer and use it in GitHub Desktop.
100.times do
user = FactoryGirl.create(:user)
form = FactoryGirl.create(:form)
# Example usage of a Submissions-storage to read/write submissions (user answers)
# It let us don't care much in application how would storage work and which database it uses
# Write a value to storage
#
# user.storage_for(form.token).store(key, value)
#
# or
#
# user.storage_for(form.token).store(array_with_fields)
#
# Get list of filled forms for user:
#
# user.storage_for(form.token).list
#
# Get list of fields with values for particular form:
#
# user.storage_for(form.token).values
# Filling out record extensions data for user:
# Storage will write it somewhere (MySQL, MongoDB)
user.storage_for(form.token).store([
{ type: "NumberField", label: "Mother's age", value: 'Nikki' },
{ type: "NumberField", label: "Father's age", value: 'Matt' },
{ type: "TextField", label: "Mother's age", value: '29' },
{ type: "TextField", label: "Father's age", value: '30' },
]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment