views:

39

answers:

2

This works just fine in my dev environment (I am rewriting a css file):

File.open(RAILS_ROOT + '\public\stylesheets\colors.css', 'w') do |w|  
    w.puts 'some_text'
end

But when I run it in my prod environment (on Dreamhost) nothing happens - the file is not modified - nothing.

What I need to be able to do is to overwrite an existing file, which I can't seem to figure out in production. I even set the chmod to 777 and that didn't change anything, it also doesn't appear that anything is showing up in the logs?

I am a noob in RoR, I appreciate the help.

A: 

I'm pretty sure you have to restart the server to see changes in production mode, even for public assets like css files. You either need to save the css changes in the database and load them dynamically, or change your environments/production.rb file to reload the static assets -but that will be really slow, obviously.

Jed Schneider
Not true at all. This is entirely driven by browser side caching. Sometimes rails will timestamp the asset url, but even that should change in production when you are doing this unless you have page caching setup.
Squeegy
Squeegy is right, css has nothing to do with the rendering engine, no matter what language it is
naspinski
+3  A: 

You are writing to a file called \public\stylesheets\colors.css when you would really like to write to a file called colors.css in /public/stylesheets/

Backslash, \, is a valid filename character in POSIX filesystems, but is the directory separator in NTFS. Change your backslashes to forward slashes.

guns
ah yes, so simple :)
naspinski
IIRC, Ruby translates `/` to the native directory delimiter in all File operations. So you can either use `File.join dir, file`, or simply `dir/file` to refer to `dir\file` on your Windows machine and `dir/file` on your Linux machine. Someone let me know if I'm wrong though.
guns