我是RoR上的一个完整的菜鸟,这是我第一次使用Ruby进行网站开发,结果证明是非常具有挑战性......第一次要学习的变量数量是......许多。我已经尝试了4天才弄清楚RoR的正确设置,但似乎我总是遇到障碍。
无论如何,这是我目前遇到的问题..我正在使用带有ruby版本2.1.5p273和rails版本4.18的Windows 7 我打算将我的应用程序部署到Heroku,所以我首先用命令创建rails应用程序:
rails new myapp --database=postgresql
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
所以我在我的bin文件夹中打开bundle,rails,rake并更改" jruby.exe" to" 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>'
现在它说了一些关于inflections.rb:1:in&#39;要求无法加载这样的文件 - thread_safe(加载错误)
不确定这意味着什么,但之后我尝试做一些这样的事情: 1.安装thread_safe gems - &gt;没有改变 2.安装activesuport gems - &gt;没有改变 3.我尝试将ruby版本更改回2.0.0,但它说&#39; activerecord -jdbcpostgresql-adapter&#39;需要jruby。
请注意,在这一点上,我仍然对ruby,jruby和postgresql一无所知。由于对我的了解有限,我对可能导致这个问题的原因的可能原因感到震惊。 所以,如果有人能指出我正确的方向,我将非常感激!答案 0 :(得分:1)
在与@elithrar的评论中进行了一些讨论后,我开始寻找jruby参与的答案,
事实证明,ruby的初始安装时间很长,即系统文件路径(可在此处访问edit syst path for windows)
原来是指向jruby \ bin,因此我将系统路径更改为另一个ruby版本(我从铁路网站下载)。只有在检查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版本。它指向正确的目的地吗?