We got a new production server for Rails apps at work. In its early life, it’s running Ubuntu and Apache (no mongrels yet, but fcgi instead). But the issue, here, is with Apache. Sort of.
In a recent deployment, I noticed that the image uploads quit working. So I glanced through the logs, and noticed that it was going from new straight to index, essentially neglecting create. Rather than POSTing to /files, it was GETting /files. I wasn’t sure what was going on. After all, it worked fine in development. (can’t keep track of how many times I’ve said that)
Then I remembered something: the action in the form (/files) matches the database table name, which attachment_fu then uses as the public directory to store the files in. So Apache was seeing /files and was trying to show that directory, in which Rails was then catching and routing to the index action. So, what now?
Well, it turns out that /files/ works just fine, whereas /files does not (notice the trailing slash). Some people say this is the fix:
1 2 3 4 | # application.rb def default_url_options(options) { :trailing_slash => true } end |
But that didn’t work for me. Maybe default_url_options only gets called on url_for, and not named routes? Or maybe it’s because I use files_path instead of files_url? Whatever the reason, setting the :trailing_slash option didn’t work for me. I could only get this to work in production by ignoring the named route (ugh) and using :url => '/files/' instead.
Anyway, you’ve been warned.








Recent Comments
There’s a new one for you. Can’t believe I stumbled ...
@Ryan, @Nick – well, I’m glad I’ve been of help, ...
Ha! Yeah, it is a little awkward. Good thing I don’t actually...
While your explanation is sound, I cannot bear the hear the audible...
I suggest looking into unobtrusive javascript, especially since you...
Update – I found out that my inclusion of jQuery was causing ...
I had something about 20% developed in PHP and got sick of it. It...