Ruby(2.1.5p273) on Rails (4.18) 部署在 Heroku 应用程序错误变化.rb:1:in 'require': 无法加载这样的文件 -- 线程_safe



我是一个完全的RoR新手,这是我第一次使用Ruby进行网站开发,结果证明它相当具有挑战性…第一次学习的变量数量是……有点太多了。我已经尝试了4天,只是为了找出RoR的正确设置,然而,我似乎总是遇到障碍。

无论如何,这是我目前遇到的问题…我使用ruby 2.1.5p273和rails 4.18版本的windows 7我打算将我的应用程序部署到Heroku,所以我首先使用命令创建rails应用程序:

rails new myapp --database=postgresql

之后检查gemfile
source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use jdbcpostgresql as the database for Active Record
gem 'activerecord-jdbcpostgresql-adapter'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyrhino'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',                                 group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# to solve tzinfo-data problem
gem 'tzinfo-data'

之后,我用git

存储应用程序
git init
git add .
git commit -m "initial commit"

然后转到localhost:3000,页面显示ruby默认页面,表明本地正在工作。然而,当我尝试将应用程序推送到heroku时,问题出现了。

我遵循这个命令:

heroku create
git push heroku master
heroku open

它原来是错误的,页面显示"应用程序错误"页面浏览了一段时间后,我发现了关于heroku日志功能,并试图找出问题,我不能很清楚地理解日志。以下是日志:

Your version of git is 1.8.4.. Which has serious security vulnerabilities.
More information here: https://blog.heroku.com/archives/2014/12/23/update_your_git_clients_on_windows_and_os_x
←[36m2015-07-16T06:28:44.016688+00:00 app[web.1]:←[0m /usr/bin/env: jruby.exe: No such file or directory
←[36m2015-07-16T06:28:44.779818+00:00 heroku[web.1]:←[0m Process exited with status 127
←[36m2015-07-16T06:28:44.798095+00:00 heroku[web.1]:←[0m State changed from starting to crashed
←[36m2015-07-16T06:28:44.799323+00:00 heroku[web.1]:←[0m State changed from crashed to starting
←[36m2015-07-16T06:28:48.416335+00:00 heroku[web.1]:←[0m Starting process with command `bin/rails server -p 12996 -e production`
←[36m2015-07-16T06:28:49.546664+00:00 app[web.1]:←[0m /usr/bin/env: jruby.exe: No such file or directory
←[36m2015-07-16T06:28:50.321059+00:00 heroku[web.1]:←[0m Process exited with status 127
←[36m2015-07-16T06:28:50.343084+00:00 heroku[web.1]:←[0m State changed from starting to crashed
←[33m2015-07-16T06:28:59.717663+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/" host=shinfithecraf
tcom.herokuapp.com request_id=38466811-0df1-418a-9e71-d8db0fb2787a fwd="36.82.86.169" dyno= connect= service= status=503 bytes=
←[33m2015-07-16T06:29:00.337303+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=sh
infithecraftcom.herokuapp.com request_id=5d15f883-9873-451e-aa2f-f23957f8f532 fwd="36.82.86.169" dyno= connect= service= status=503 b
ytes=
←[32m2015-07-16T06:35:50.725201+00:00 heroku[api]:←[0m Starting process with command `rails console` by myemail@gmail.com
←[35m2015-07-16T06:35:54.225700+00:00 heroku[run.4903]:←[0m Awaiting client
←[35m2015-07-16T06:35:54.257165+00:00 heroku[run.4903]:←[0m Starting process with command `rails console`
←[35m2015-07-16T06:35:54.635356+00:00 heroku[run.4903]:←[0m State changed from starting to up
←[35m2015-07-16T06:35:56.469745+00:00 heroku[run.4903]:←[0m Process exited with status 127
←[35m2015-07-16T06:35:56.507341+00:00 heroku[run.4903]:←[0m State changed from up to complete
←[36m2015-07-16T06:54:37.484647+00:00 heroku[web.1]:←[0m State changed from crashed to starting
←[36m2015-07-16T06:54:41.906605+00:00 heroku[web.1]:←[0m Starting process with command `bin/rails server -p 20328 -e production`
←[36m2015-07-16T06:54:44.137100+00:00 app[web.1]:←[0m /usr/bin/env: jruby.exe: No such file or directory
←[36m2015-07-16T06:54:45.035554+00:00 heroku[web.1]:←[0m Process exited with status 127
←[36m2015-07-16T06:54:45.047325+00:00 heroku[web.1]:←[0m State changed from starting to crashed
←[32m2015-07-16T07:18:35.619583+00:00 heroku[api]:←[0m Starting process with command `rails console` by myemail@gmail.com
←[35m2015-07-16T07:18:41.441770+00:00 heroku[run.9530]:←[0m Awaiting client
←[35m2015-07-16T07:18:41.482683+00:00 heroku[run.9530]:←[0m Starting process with command `rails console`
←[35m2015-07-16T07:18:44.122593+00:00 heroku[run.9530]:←[0m Process exited with status 127
←[35m2015-07-16T07:18:44.138803+00:00 heroku[run.9530]:←[0m State changed from up to complete
←[35m2015-07-16T07:18:41.633345+00:00 heroku[run.9530]:←[0m State changed from starting to up

我试图通过学习阅读日志文件来解决这个问题,发现问题实际上在

  ←[36m2015-07-16T06:28:44.016688+00:00 app[web.1]:←[0m /usr/bin/env: jruby.exe: No such file or directory

所以我打开bundle,rails,rake在我的bin文件夹中,并将"jruby.exe"更改为"ruby",我不知道为什么这些文件实际上使用jruby.exe,但它似乎有效,问题消失了,然而,在heroku上打开网页仍然显示"应用程序错误",另看日志文件显示:

←[36m2015-07-16T07:21:14.512070+00:00 heroku[web.1]:←[0m Starting process with command `bin/rails server -p 19013 -e production`
←[36m2015-07-16T07:21:01.692937+00:00 heroku[web.1]:←[0m State changed from crashed to starting
←[36m2015-07-16T07:21:17.990817+00:00 app[web.1]:←[0m /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/infle
ctor/inflections.rb:1:in `require': cannot load such file -- thread_safe (LoadError)
←[36m2015-07-16T07:21:17.990839+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_suppor
t/inflector/inflections.rb:1:in `<top (required)>'
←[36m2015-07-16T07:21:17.990847+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_suppor
t/inflections.rb:1:in `<top (required)>'
←[36m2015-07-16T07:21:17.990849+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_suppor
t/inflector/methods.rb:3:in `require'
←[36m2015-07-16T07:21:17.990850+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_suppor
t/inflector/methods.rb:3:in `<top (required)>'
←[36m2015-07-16T07:21:17.990846+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_suppor
t/inflections.rb:1:in `require'
←[36m2015-07-16T07:21:17.990855+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_suppor
t.rb:25:in `require'
←[36m2015-07-16T07:21:17.990852+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_suppor
t/dependencies/autoload.rb:1:in `require'
←[36m2015-07-16T07:21:17.990858+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.8/lib/action_dispatch.
rb:24:in `require'
←[36m2015-07-16T07:21:17.990862+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands/ser
ver.rb:3:in `require'
←[36m2015-07-16T07:21:17.990853+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_suppor
t/dependencies/autoload.rb:1:in `<top (required)>'
←[36m2015-07-16T07:21:17.990856+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_suppor
t.rb:25:in `<top (required)>'
←[36m2015-07-16T07:21:17.990863+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands/ser
ver.rb:3:in `<top (required)>'
←[36m2015-07-16T07:21:17.990859+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.8/lib/action_dispatch.
rb:24:in `<top (required)>'
←[36m2015-07-16T07:21:17.990865+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands/com
mands_tasks.rb:128:in `require'
←[36m2015-07-16T07:21:17.990869+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands/com
mands_tasks.rb:40:in `run_command!'
←[36m2015-07-16T07:21:17.990867+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands/com
mands_tasks.rb:74:in `server'
←[36m2015-07-16T07:21:17.990875+00:00 app[web.1]:←[0m   from bin/rails:4:in `<main>'
←[36m2015-07-16T07:21:17.990866+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands/com
mands_tasks.rb:128:in `require_command!'
←[36m2015-07-16T07:21:17.990870+00:00 app[web.1]:←[0m   from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands.rb:
17:in `<top (required)>'
←[36m2015-07-16T07:21:17.990873+00:00 app[web.1]:←[0m   from bin/rails:4:in `require'
←[36m2015-07-16T07:21:18.817510+00:00 heroku[web.1]:←[0m Process exited with status 1
←[36m2015-07-16T07:21:18.834033+00:00 heroku[web.1]:←[0m State changed from starting to crashed
←[32m2015-07-16T07:21:50.556289+00:00 heroku[api]:←[0m Starting process with command `rails console` by hansin.ciputra@gmail.com
←[35m2015-07-16T07:21:54.774130+00:00 heroku[run.3007]:←[0m Awaiting client
←[35m2015-07-16T07:21:55.080890+00:00 heroku[run.3007]:←[0m State changed from starting to up
←[35m2015-07-16T07:21:55.047872+00:00 heroku[run.3007]:←[0m Starting process with command `rails console`
←[35m2015-07-16T07:21:57.836920+00:00 heroku[run.3007]:←[0m State changed from up to complete
←[35m2015-07-16T07:21:57.818989+00:00 heroku[run.3007]:←[0m Process exited with status 1
←[32m2015-07-16T07:37:13.247117+00:00 heroku[api]:←[0m Starting process with command `rails console` by hansin.ciputra@gmail.com
←[35m2015-07-16T07:37:17.172613+00:00 heroku[run.5048]:←[0m Awaiting client
←[35m2015-07-16T07:37:17.245003+00:00 heroku[run.5048]:←[0m Starting process with command `rails console`
←[35m2015-07-16T07:37:17.513511+00:00 heroku[run.5048]:←[0m State changed from starting to up
←[35m2015-07-16T07:37:20.511063+00:00 heroku[run.5048]:←[0m Process exited with status 1
←[35m2015-07-16T07:37:20.526444+00:00 heroku[run.5048]:←[0m State changed from up to complete
←[32m2015-07-16T07:53:39.298710+00:00 heroku[api]:←[0m Starting process with command `rails console` by hansin.ciputra@gmail.com
←[35m2015-07-16T07:53:43.115988+00:00 heroku[run.2827]:←[0m Awaiting client
←[35m2015-07-16T07:53:43.154089+00:00 heroku[run.2827]:←[0m Starting process with command `rails console`
←[35m2015-07-16T07:53:43.359493+00:00 heroku[run.2827]:←[0m State changed from starting to up
←[35m2015-07-16T07:53:45.772926+00:00 heroku[run.2827]:←[0m State changed from up to complete
←[35m2015-07-16T07:53:45.762212+00:00 heroku[run.2827]:←[0m Process exited with status 1

浏览了一段时间后,我发现可以使用命令

更清楚地查找问题。
heroku run rails console

,结果如下:

Your version of git is 1.8.4.. Which has serious security vulnerabilities.
More information here: https://blog.heroku.com/archives/2014/12/23/update_your_git_clients_on_windows_and_os_x
Running `rails console` attached to terminal... up, run.9621
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/inflector/inflections.rb:1:in `require': cannot load such f
ile -- thread_safe (LoadError)
        from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/inflector/inflections.rb:1:in `<top (required)
>'
        from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/inflections.rb:1:in `require'
        from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/inflections.rb:1:in `<top (required)>'
        from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/inflector/methods.rb:3:in `require'
        from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/inflector/methods.rb:3:in `<top (required)>'
        from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies/autoload.rb:1:in `require'
        from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies/autoload.rb:1:in `<top (required)
>'
        from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support.rb:25:in `require'
        from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support.rb:25:in `<top (required)>'
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails.rb:5:in `require'
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails.rb:5:in `<top (required)>'
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/all.rb:1:in `require'
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/all.rb:1:in `<top (required)>'
        from /app/config/application.rb:3:in `require'
        from /app/config/application.rb:3:in `<top (required)>'
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:146:in `require'
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:146:in `require_application_and_e
nvironment!'
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:68:in `console'
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>'
        from /app/bin/rails:4:in `require'
        from /app/bin/rails:4:in `<main>'

now它说明了一些变化。rb:1:in 'require cannot load such file——thread_safe(load Error)

不知道这是什么意思,但之后我试着做一些这样的东西:1. 安装thread_safe gems ->没有改变2. 安装activesupport gems ->没有改变3.我尝试将ruby版本更改回2.0.0,但它说'activerecord-jdbcpostgresql-adapter'需要jruby .

在这一点上,我对ruby,jruby和postgresql仍然知之甚少。以我有限的知识,我被可能是这个问题的原因的数量所摧毁。所以,如果有人能给我指出正确的方向,我将非常感激!

在@elithrar的评论中进行了一些讨论之后,我开始寻找为什么涉及jruby的答案。原来是在某个地方,ruby的初始安装,系统文件路径(可以在这里访问编辑系统路径为windows)原来指向jrubybin,因此我将系统路径更改为另一个ruby版本(我从rail网站下载)。确认ruby -v正确后,才执行bundle install

这解决了上面提到的所有问题,gemfile bin不再指向jruby.exe,并且postgresql的gemfile不再显示activerecord-jdbcpostgresql-adapter,而是显示gem "pg"

有一个小问题,然而,当试图做bundle install,它告诉我,Your Ruby version is 2.1.5, but your Gemfile specified 2.0.0简单地编辑gemfile在ruby "2.0.0"ruby "2.1.5"修复它

之后,安装ruby并按照教程将其推送到heroku,运行顺利

我的建议:

对于那些有同样问题的人,试着查看系统路径下的ruby版本。它指向正确的目的地了吗?

最新更新