生产环境执行rails console命令显示默认帮助页问题求助
生产服务器rbenv环境下Rails控制台无法启动,显示默认帮助页
问题详情
进入项目目录执行启动命令时,未打开Rails控制台,反而显示rails默认帮助页(rails new使用说明):
cd $HOME/rails/current RAILS_ENV=production bundle exec rails console
也尝试过以下命令,问题依旧:
RAILS_ENV=production rbenv exec bundle exec rails c
环境信息
which ruby /home/myuser/.rbenv/shims/ruby ruby -v ruby 2.6.10p210 (2022-04-12 revision 67958) [x86_64-linux] rbenv local 2.6.10 uname -a Linux myserver 5.15.0-57-generic #63-Ubuntu SMP Thu Nov 24 13:43:17 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
调试结果
执行以下命令均返回相同的Rails版本:
rails -v bundle exec rails -v rbenv exec bundle exec rails -v # 输出:Rails 4.2.11.3
排查与解决步骤
确认当前目录为Rails项目根目录
执行ls -la检查是否存在config/、app/等Rails核心目录;如果current是符号链接,用ls -l $HOME/rails/current确认指向的路径是否正确。校验bundle依赖加载
执行bundle show rails,确认输出路径属于当前项目的vendor/bundle或rbenv环境下的gem目录,而非系统全局gem。若路径异常,重新执行生产环境依赖安装:bundle install --without development test直接调用控制台底层入口
Rails 4.x版本可尝试通过脚本入口启动:RAILS_ENV=production bundle exec ruby script/rails console或使用bundle定位的rails可执行文件路径启动:
RAILS_ENV=production $(bundle show rails)/bin/rails console修复rbenv环境冲突
执行rbenv global确认全局Ruby版本与项目local版本一致;若不一致,执行rbenv rehash刷新shims后重试命令。简化环境变量传递方式
直接在console命令后指定环境名,避免环境变量传递问题:bundle exec rails console production
内容的提问来源于stack exchange,提问作者Besi
相关产品推荐
相关产品推荐

