在OpenShift上使用Rails控制台

5
我将rails应用程序部署到openshift上,它工作正常,但我无法在生产服务器上运行'rails console'。它给了我这个错误。我该如何解决?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法解决它。
rails c 错误:
Warning: You're using Rubygems 1.8.24 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
/opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require': cannot load such file -- bundler/setup (LoadError)
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require'
from /var/lib/openshift/5429e72a500446dfee000197/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/spring-1.1.3/lib/spring/commands.rb:33:in `<module:Spring>'
from /var/lib/openshift/5429e72a500446dfee000197/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/spring-1.1.3/lib/spring/commands.rb:4:in `<top (required)>'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require'
from /var/lib/openshift/5429e72a500446dfee000197/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/spring-1.1.3/lib/spring/application.rb:77:in `preload'
from /var/lib/openshift/5429e72a500446dfee000197/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/spring-1.1.3/lib/spring/application.rb:140:in `serve'
from /var/lib/openshift/5429e72a500446dfee000197/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/spring-1.1.3/lib/spring/application.rb:128:in `block in run'
from /var/lib/openshift/5429e72a500446dfee000197/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/spring-1.1.3/lib/spring/application.rb:122:in `loop'
from /var/lib/openshift/5429e72a500446dfee000197/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
from /var/lib/openshift/5429e72a500446dfee000197/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in `<top (required)>'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require'
from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require'
from -e:1:in `<main>'

rubygems-update错误:

[appname.rhcloud.com repo]\> update_rubygems
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /opt/rh/ruby193/root/usr/local/share/ruby

你正在使用哪些命令?我对openshift不是很了解,但快速搜索表明以下命令可能有用: - bnjmn
cd app-root/repo && bundle exec rails console RAILS_ENV=production - bnjmn
当我使用“rails c”命令时,它会忽略“c”,并返回一个似乎只写了“rails”的结果。当我写“bundle exec rails c”时,它会给出上面的错误。在第二部分中,“gem install rubygems-update”运行良好并安装了gem。但是然后“update_rubygems”会给出第二个错误。 - sayginburak
4个回答

4

我遇到了同样的问题,请尝试这样运行它:

RAILS_ENV=production bundle exec rails console

同时确保您在运行时将其放置在~/app-root/repo目录中


1
我尝试过了,但是不起作用。但是今天我使用ruby-2.0 cartridge部署了我的应用程序,控制台可以工作。此时出现了其他问题。 - sayginburak

2

更新 RubyGems:

gem update --system

如果那样做不能解决问题,尝试Spring的建议并运行:

gem pristine --all

gem update --system在一行中工作了两个命令,最后给出了相同的错误。 gem pristine --all 给出了以下信息: 正在将宝石还原为原始状态... 找不到ZenTest-4.8.1的缓存宝石,正在尝试获取... 正在获取:ZenTest-4.8.1.gem(100%) 错误:执行gem时...(Gem :: FilePermissionError) 您没有写入/opt/rh/ruby193/root/usr/share/gems目录的权限。这个写入权限是什么?我该如何获得它?人们说PaaS上不需要root访问权限。 - sayginburak
那么我的回答没有帮到你,很抱歉。这是一个所有权问题,而不是执行问题。你是否以管理员身份登录?糟糕的解决方案可能是sudo gem update --system,但正确的方法应该是chown rubygems,这样你就有权限了,但我对bash不够熟练,无法为你提供详细指导。 - beaglebets
我猜Redhat不允许我以root身份登录,但我不确定我找不到它。没有人提到过这一点。http://stackoverflow.com/questions/13296732/root-privileges-on-openshift 大家都说有另一种方法可以做到。 - sayginburak

1

在OpenShift上运行4.1.4 Rails cartridge时,我无法使用任何gem installbundle exec的解决方案。我的解决方法是在app-root/repo中运行RAILS_ENV=production bin/rails c


1
问题在于有多个捆绑可执行文件,系统正在使用错误的可执行文件。
找到正确的 bundle 可执行文件。在我的情况下,它位于 ~/.gem/bin/bundle
如果找不到,请安装它 gem install bundler
然后在 ~/app-root/repo 中运行 ~/.gem/bin/bundle exec rails console production

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接