The little things
Posted by Sam
It's the little things in life that make a big difference. I recently ran into a problem where I thought ImageMagick was corrupting my images when it resized them. Turns out the problem was the database. In my migration I'd only specified :binary for the datatype. It looked like this.
create_table :db_files do |t|
Well in MySQL this means that it defaults to a Blob which only holds 64k. Originally the images were being scaled to 182x182 so this didn't present a problem as all the images seemed to come in under 64k. A couple days later I had to adjust this to 250x250 and then we started getting 'corrupt' images. Turns out some images just needed more space and some didn't. I looked through my Agile Web Development in Rails book and only saw a Binary datatype and didn't find an obvious way to make it bigger. Then I stumbled across a page that talked about setting the size to have a bigger limit and ActiveRecord will automatically give you a larger Blob datatype. In order to accommodate the bigger images I created the following migration.
t.column :data, :binary
end
class ChangeMaxImageSize < ActiveRecord::Migration
Woo Hoo! Thankfully that solved it.
def self.up
change_column :db_files, :data, :binary, :limit => 512.kilobytes
end
def self.down
change_column :db_files, :data, :binary
end
end
Some frameworks look great on the surface and the more you use them the uglier they get. That was certainly my experience with Struts. It created as many problems as it solved. I've had a very different experience with Rails. It constantly surprises me with how well thought out and usable it is. I'm not a Rails fanboy I just like things that work and for most cases Rails just works.
Tags: rubyonrails
Comments
Be the first to leave a comment.