Wednesday, June 20, 2007
« Why is my IsOneWay operation blocking? | Main | Solving A/BC + D/EF + G/HI = 1 with Ruby... »
I'm in the process of deploying a Rails app, and up until a few minutes ago I was having problems getting acts_as_attachement and attachment_fu to work.  I originally started development with acts_as_attachement since I was naive and didn't know there was something better.  After looking for a fix for the issue I was seeing, I came across attachment_fu and came to see that it was superior and would undoubtedly solve my issue.  It didn't....however, the upgrade process was painless and I got some extra goodies so all was good.  For those interested, the extra goodies include pluggable image processors (RMagick, MiniMagick, and ImageScience) as well as an option to store files with Amazon S3.

With attachment_fu installed, I was sure my problem would be resolved.  I suspected the issue I was having was related to RMagick image resizing since I'm deploying to a shared hosting account on TextDrive, and RMagick has quite a reputation for hogging up lots of memory and causing havoc on shared accounts.  After switching over to attachment_fu and to MiniMagick as my image processor I was still seeing my issue, so I realized it had to be something else.

Before going onto the solution, let me explain the problem that was occuring.  When I was submitting a form for an attachment_fu model I was immediately being redirected back to the index page.  Every once in a while the form would appear to be submitting, hang, and eventually hose the lighttpd process.  As I mentioned above, I first suspected the problem was related to image resizing being done by RMagick but I was able to reproduce the problem on a non image attachment_fu model object.  After digging around on the web and coming up empty, I ended up checking out the Rails log file to see if I could figure out what was going on.  Examining the production.log showed that I was going from the :new action, directly to the :index action.  Since I was submitting a form, I should have seen a hit on the :create action for my controller.  This led me to search google for a slightly better phrase which eventually landed me at this "Form doesn't trigger create in production" forum post, as well as this related post on Ruby Forum.

It turns out the problem is due to the way that attachment_fu stores the files uploaded on the file system.  attachment_fu stores the files in a folder with the same name as the model within the public folder.  This causes issues since the url for the controller, as well as the directory for storing files have the same URL.  Fortunately the fix is as simple as adding the following to your application.rb file.
def default_url_options(options)
{ :trailing_slash => true }
end

Deployment is such fun, isn't it! :)


 |  | 
Wednesday, October 24, 2007 1:27:33 PM (Eastern Daylight Time, UTC-04:00)
Wow! Thanks for posting this, it saved me hours of debugging!
Thursday, December 06, 2007 12:30:03 AM (Eastern Standard Time, UTC-05:00)
You saved me from lot's of troubles. While deploying my first Rails app I was experiencing the same problem with uploading images. These few lines of code really saved me. :)

Thank you for writing this post.

Cheers,

Sasha
Monday, April 07, 2008 8:12:02 PM (Eastern Daylight Time, UTC-04:00)
Thank you!

I was looking at my logs experiencing the same problem you had. Reading this post saved me many hours of tracking down why it was happening.
Matt
Tuesday, July 08, 2008 9:21:49 AM (Eastern Daylight Time, UTC-04:00)
Thanks for posting your experience about this! I was really stuck and I had no idea what to google for when diagnosing this problem. I tried "create action incorrectly redirects with attachment_fu" but came up fruitless. Finally, a colleague pointed me to this page.

Thanks!
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):