Hi All,
Hoping this is an easy question… Can I loop through add_columns?
I’ve got a bunch of columns that I need to add to a table… I don’t
really want to type “add_column” 30 times… and then “remove_column”
another 30 times
Is there an easy way to just loop through the is so my migration doesn’t
look like this?:
def self.up
add_column :enrollments, :fname
add_column :enrollments, :lname
add_column :enrollments, :email, :string
add_column :enrollments, :school_type, :string
add_column :enrollments, :number_of_students, :string
add_column :enrollments, :school_name, :string
add_column :enrollments, :internet, :boolean
add_column :enrollments, :internet_quality, :string
#(and on and on and on.....)
end
def self.down
remove_column :enrollments, :fname
remove_column :enrollments, :lname
remove_column :enrollments, :email
remove_column :enrollments, :school_type
remove_column :enrollments, :number_of_students
remove_column :enrollments, :school_name
remove_column :enrollments, :internet
remove_column :enrollments, :internet_quality
#blah blah blah...
end
Thanks!