Rails 3 中的权限错误
我的rails3应用程序使用madeleine(http://madeleine.rubyforge.org/)来存储对象。
m = SnapshotMadeleine.new("data_dir") {
Array.new
}
该代码在我的本地计算机上运行良好,但在服务器上引发错误。
Permission denied - data_dir
跟踪是,
/home/foo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.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'
无论 data_dir 目录是否存在,都会发生此错误。我把data_dir目录和根目录的权限改成了777,还是报错。
我将 Rails 3.0 和 ruby 1.9.2-p290 与 rvm 结合使用,并启动服务器并
rails s -d -e production
编写了一个简单的测试代码,并且没有任何错误。
require 'rubygems'
require 'madeleine'
madeleine = SnapshotMadeleine.new("data_dir") do
Array.new
end
madeleine.take_snapshot
是什么原因导致这个问题呢?
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/fileutils.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测 SnapshotMadeleine.new 尝试创建一个目录,因为错误提到了 FileUtils.mkdir。
您应该让 Rails 用户有权写入 Web 应用程序的根目录(?),以便它可以创建文件夹,而不仅仅是写入已存在的文件夹。
或者修改 SnapshotMadeleine 的源,以便它不会创建该目录(如果该目录已存在)。
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.