Set RAILS_ENV properly and fix an issue with image_optim