Ruby on Rails - Can't seem to figure out how to write/modify files on the live site
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 - nothin开发者_开发技巧g.
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.
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.
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.
精彩评论