Skip to content

Instantly share code, notes, and snippets.

@ratnikov
Forked from silasb/gist:296306
Created February 5, 2010 22:45
Show Gist options
  • Select an option

  • Save ratnikov/296344 to your computer and use it in GitHub Desktop.

Select an option

Save ratnikov/296344 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 puts "surveys: #{SurveyItem.all.inspect}"
12 SurveyItem.all.each do |item|
puts "alternatives for: #{item.response_alternatives.inspect}"
13 item.response_alternatives.each_with_index do |alt, index|
puts "alt: #{alt.inspect}"
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