Crusher Development!

October 18, 2007

Flash uploader, why not?

Filed under: bulk, flash, images, java, uploader — Russell @ 7:27 am

We all knew that we needed some sort of uploader to help with bulk uploading images in our app. The problem is, my engineering experience doesn’t involve any technology I could use to write a component myself. Which would be fine at a large company, because I would take a month or two, decide on what technology was best, do some prototyping and then build a component. When our team consists of 3 people that just isn’t an option.

Instead I did some research for a couple hours. Decided to go with flash instead of java. Found a five year old company that made a flash uploader for $39. Built the feature out using the demo version. Shared it with the team to experiment, we all liked it, and that was it. Now there are most likely better solutions out there, but with around 2 – 3 days of time we were able to get a great feature that we are happy with that will move us ahead in helping make photo sharing easier on our site.

If any of you RoR people are going to try and use this uploader there were a couple things I had to do:

The uploader comes up after an ajax request so it isn’t on the intial page. IE did not care for this and threw a bunch of JS errors. This could have been because of the JS hooks provided by the flash component. However, hosting the uploader in an iframe fixed that problem and allowed me to continue on.

After an image is uploaded to the server there is a JS hook that is called on the client. I used this hook to send out an ajax request asking for the image that was just uploaded. This made it so that as each image is uploaded a thumbnail will appear in view on the client.

FireFox on the mac causes the uploader to disappear if opacity is used.  So, when the uploader is brought to view I dynamically disable opacity and restore it when uploading is finished.

If anyone has more experience with this I’d certainly like to hear about it. Picture is below, and use the site and try it out for yourself :-)
photo uploader

October 5, 2007

RoR? Don’t forget about script/console :-)

Filed under: command window, debugging, mysql, script/console — Russell @ 4:05 pm

When programming javascript Firebug has a console that lets you type in javascript and fire it against an open window. The Tandy TRS-80 command line let me type in basic programs on the fly. I also have faint recollections of having a command window that came in handy with other languages. However, none of these ever proved incredibly useful for me, or left any strong imprint on my impressionable mind.

That is, until I started working with RoR and was introduced to the script/console. Hello “script/console”, nice to meet you :-) At first it seemed mildly useful, but the other day after a minor hiccup it proved itself extremely helpful.

The biggest thing to make sure and not overlook is the ability to execute commands like this:

>>user_list = User.find(:all)
>>user_list.each{ |u| u.update_attributes(:is_crazy, true) if u.has_duplicate_phone_numbers? }

I’ve done a lot of work with databases, but I am by no means a SQL guru. These 2 lines of code took me under a minute to write and there aren’t enough users in our system to have to worry about the execution time. The hiccup we had the other day involved sending out our monthly product mailer. We managed to have 2 servers that were asked to create mailer messages, so everyone started getting 2 of our product mailers! Eek!

Not the end of the world, but not so fun. We shut down the mailer. 1/3 of the mail did not get sent at all, a handful of people only got one mail, and the rest received 2 mails. So, I needed to enable only 1 mailer for the 1/3 of the people who hadn’t received any mails, and turn the rest of the records to a failed status. Thank you script/console. Literally under 2 minutes I was able to do some command line work and bring the mailer back up. I’m slowly moving myself away from directly doing sql, and loving every inch away I get.

You can see our admin interface – the fails are the duplicate mailers that I automatically failed:
show mailer problem

Blog at WordPress.com.