You could try using a StringIO as a workaround On Wed, Jul 28, 2010 at 16:35, Justin <[email protected]> wrote: > Hi folks! Can someone help me find the problem with my migration, > below? It's working fine on my local environment, but when I run it > in Heroku I get 'an instance of IO needed' error. I shouldn't need an > IO instance since I'm passing a string to the method--or at least > that's the intent. The intent of the code is to read from the > database a serialized instance of a Grid, deserialize the object, > create a StaggeredGrid based on the contents, then serialize the new > object. I can't do this directly at the ActiveRecord level because > the active record object that owns the grid is expecting a > StaggeredGrid and fails validation. > > Any ideas? Thanks in advance! > > === migration file: > > # This seems to be required for YAML::load since the Grid class is > never > # directly invoked > require 'lib/grid' > require 'lib/staggered_grid' > > class GridToStaggeredGrid < ActiveRecord::Migration > def self.up > say_with_time "Changing existing grids to staggered grids..." do > suppress_messages do > grids = execute "SELECT id, grid FROM grids" > grids.each do |grid| > old_grid = YAML::load(grid[1]) > new_grid = StaggeredGrid.new old_grid.row_count, > old_grid.column_count > old_grid.each_with_coordinates do | cell, row, column | > new_grid[row][column] = cell > end > result = execute "UPDATE challenges SET grid = > '#{YAML::dump(new_grid)}' WHERE id = #{grid[0]}" > end > end > end > end > > def self.down > say_with_time "Changing existing staggered grids back to grids..." > do > suppress_messages do > grids = execute "SELECT id, grid FROM grids" > grids.each do |grid| > old_grid = YAML::load grid[1] > new_grid = Grid.new old_grid.row_count, > old_grid.column_count > old_grid.each_with_coordinates do | cell, row, column | > new_grid[row][column] = cell > end > result = execute "UPDATE challenges SET grid = > '#{YAML::dump(new_grid)}' WHERE id = #{grid[0]}" > end > end > end > end > end > > -- > You received this message because you are subscribed to the Google Groups > "Heroku" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/heroku?hl=en. > >
-- You received this message because you are subscribed to the Google Groups "Heroku" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/heroku?hl=en.
