Permission error in rails 3
My rails3 application uses madeleine(http://madeleine.rubyforge.org/) to store object.
m = SnapshotMadeleine.new("data_dir") {
Array.new
}
This code works fine on my local machine, but raises an error on the server.
Permission denied - data_dir
Trace is,
/home/foo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fi开发者_Python百科leutils.rb:243:in `mkdir'
/home/foo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:243:in `fu_mkdir'
/home/foo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:217:in `block (2 levels) in mkdir_p'
/home/foo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:215:in `reverse_each'
/home/foo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:215:in `block in mkdir_p'
/home/foo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:201:in `each'
/home/foo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:201:in `mkdir_p'
madeleine (0.7.3) lib/madeleine.rb:319:in `ensure_directory_exists'
madeleine (0.7.3) lib/madeleine.rb:314:in `initialize'
madeleine (0.7.3) lib/madeleine.rb:48:in `new'
madeleine (0.7.3) lib/madeleine.rb:48:in `new'
This error happens either data_dir directory is already exists or not. I changed the permission of data_dir directory and the root directory 777, but the error still happens.
I use rails 3.0 and ruby 1.9.2-p290 with rvm, and I launch the server with
rails s -d -e production
I wrote a simple test code, and it worked with no errors.
require 'rubygems'
require 'madeleine'
madeleine = SnapshotMadeleine.new("data_dir") do
Array.new
end
madeleine.take_snapshot
What causes this problem?
I'm guessing that SnapshotMadeleine.new tries to create a directory given that the error mentions FileUtils.mkdir.
You should make that the rails user has permission to write to the root(?) of the web app so that it can create the folder, rather than just write to the folder that already exists. Alternatively modify the source of SnapshotMadeleine so it doesn't create the directory if it already exists.
精彩评论