Q:

Rails File I/O: What works in Ruby doesn't work in Rails?

So, I wrote a simple Ruby class, and put it in my rails /lib directory. This class has the following method:
def Image.make_specific_image(paths, newfilename)
  puts "making specific image"
  @new_image = File.open(newfilename, "w")
  puts @new_image.inspect
  @@blank.each(">") do |line|
    puts line + "~~~~~"
    @new_image.puts line
    if line =~ /<g/
      paths.each do |p|
        puts "adding a path"
        puts p
        @new_image.puts p
      end
    end
  end    
end

Which creates a new file, and copies a hardcoded string (@@blank) to this file, adding custom content at a certain location (after a g tag is found).
If I run this code from ruby, everything is just peachy.
HOWEVER, if I run this code from rails, the file gets CREATED, but is then empty. I've inspected each line of the code: nothing I'm trying to write to the file is nil, but the file is empty nonetheless.
I'm really stumped here. Is it a permissions thing? If so, why on EARTH would Rails have the permissions necessary to MAKE a file, but then not WRITE to the file it made?
Does File I/O somehow work differently in rails?
Specifically, I have a model method that calls:
Image.make_specific_image(paths, creature.id.to_s + ".svg")

which succesfully makes a file of the type "47.svg" that is empty.

A:

Have you tried calling close on the file after you're done writing it?  (You could also use the block-based File.open syntax, which will automatically close once the block is complete).  I'm guessing the problem is that the writes aren't getting flushed to disk.

