So, developing a Rails App on a PC is usually pretty straightforward. For the most part, my code on a test machine can be upload to a linux server and work fine. Further, most code examples found online also work.
There is only 2 gotchas I’ve found so far, and they both have to do with file uploads.
1. File would be corrupt on Windows
I was using some code I found online to write a file on the server. It was an image file uploaded to the rails server, but when the image displayed on the webpage, it was corrupted. So, how could I get rid of the corrupted image? Here’s the solution from http://wiki.rubyonrails.org/rails/pages/HowtoUploadFiles
Note for Windows: to avoid corrupting binary files, you must call File.open in binary mode. Change the “w” flag to “wb”, like this:
2. File would not always upload on a windows server.
I was raking my brain over this one, but fortunately someone else had already solved it (which so far has been a very common trend in the rails world):
http://www.railsweenie.com/forums/3/topics/1257
It turns out that the file handling in windows is a bit weird, so you just have to wait for it to catch up….
So, how to deal with these in the real world? After all, in development its fine to wait for a second for a file upload, but that is not okay on a production web server….
Well, the way I dealt with it is by using configurations. I have to environment.rb files. One is called environment.online.rb, and the other is environment.rb. This was suggested by my web host. Since it is a shared host, the way a rails app is set to production mode is the flag
ENV['RAILS_ENV'] ||= ‘production’
In environment.online.rb.
When I deploy an app, I just use the .online file by renaming it. This is slightly less than ideal, since it isn’t very DRY (don’t repeat yourself), but since I don’t control the web server on a shared host, I don’t have much choice… Since I have 2 files anyway, I set another flag for myself, in this case I just have the flag:
ON_WINDOWS = false //in envrionment.online.rb
ON_WINDOWS = true //in envrionment.rb
I’m sure that ruby has a way of checking the platform, but this was just easier and quicker…