Ruby on Rails:使用“rails 生成控制器欢迎”时权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23822491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ruby on Rails: permission denied when using "rails generate controller welcome"
提问by windrider297
I used Ruby on Rails on Red Hat server. When I trying to generate a controller file, I got this error:
我在 Red Hat 服务器上使用了 Ruby on Rails。当我尝试生成控制器文件时,出现此错误:
[ec2-user@ip-172-31-22-128 testApp4]$ rails generate controller welcome
/home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `initialize': Permission denied @ rb_sysopen - /tmp/spring/fea371aaf9d69cfa58bd12f69b3f1bf6.pid (Errno::EACCES)
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `open'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `open'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `initialize'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:14:in `new'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:14:in `boot'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:43:in `block in boot_server'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:41:in `fork'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:41:in `boot_server'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:24:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:23:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /home/ec2-user/testApp4/bin/spring:16:in `require'
from /home/ec2-user/testApp4/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
回答by James Woodrow
I solved that problem by running
我通过运行解决了这个问题
sudo chmod -R 1777 /tmp
hope this helps other people like me who would prefer not having to deactivate the spring gem
希望这能帮助像我这样不想停用 spring gem 的其他人
回答by SerKnight
It needs ownership to write the re-write the pid for each server start.
它需要所有权来为每个服务器启动重写 pid。
I had to run it with my full local path & sudo
我必须使用完整的本地路径和 sudo 运行它
$ sudo chmod -R 777 /Users/MyName/Desktop/projects/my_project/tmp/
$ sudo chmod -R 777 /Users/MyName/Desktop/projects/my_project/tmp/
回答by Blaskovicz
I took a look at the library that's trying to write the pid file, lib/spring/env.rb.
我查看了试图编写 pid 文件的库,lib/spring/env.rb.
The function in question tries to create a temporary directory at the same location each time unless the XDG_RUNTIME_DIRis set:
有问题的函数每次都尝试在同一位置创建一个临时目录,除非XDG_RUNTIME_DIR设置:
path = Pathname.new(File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, "spring"))
path = Pathname.new(File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, "spring"))
Setting said variable to a unique directory does the trick for me:
将所述变量设置为一个唯一的目录对我来说很有用:
export XDG_RUNTIME_DIR=/tmp/`whoami`
回答by Debadatt
Missing permission for tmp folder to writable . run chmod 777 tmp/
缺少 tmp 文件夹的 writable 权限。跑chmod 777 tmp/
回答by WesternGun
Or,
或者,
export XDG_RUNTIME_DIR=/run/user/${id -u}
to change this system variable. id -ureturns your UID(user id), which is the dir name where you have access to write/read under /run/user/.
更改此系统变量。id -u返回您的 UID(用户 ID),这是您有权在/run/user/.

