Skip to content

Instantly share code, notes, and snippets.

@silasb
Created February 5, 2010 21:53
Show Gist options
  • Save silasb/296306 to your computer and use it in GitHub Desktop.
Save silasb/296306 to your computer and use it in GitHub Desktop.
1 class CreateSurveyResponseAlternatives < ActiveRecord::Migration
2 def self.up
3 create_table :survey_response_alternatives do |t|
4 t.string :name
5 t.string :value
6 t.integer :position
7 t.references :survey_item
8 end
9
10 #SurveyResponseAlternative.reset_column_information
11
12 SurveyItem.all.each do |item|
13 item.response_alternatives.each_with_index do |alt, index|
14 if !alt.blank?
15 p SurveyResponseAlternative.create!(:survey_item => item, :name => alt, :value => alt.value, :position => index)
16 end
17 end
18 end
19 end
20
21 def self.down
22 drop_table :survey_response_alternatives
23 end
24 end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment