“bin/rails:没有这样的文件或目录”,在 Heroku 上有 Ruby 2 和 Rails 4

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17583439/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:19:01  来源:igfitidea点击:

"bin/rails: No such file or directory" w/ Ruby 2 & Rails 4 on Heroku

ruby-on-railsrubyherokuruby-on-rails-4ruby-2.0

提问by Justin Garrick

While following the Rails 4 Betaversion of Michael Hartl's Ruby on Rails Tutorial, my app fails to start on Heroku, but runs fine locally with bundle exec rails server. Checking heroku logs -treveals the following error:

在遵循Michael Hartl 的Ruby on Rails 教程的 Rails 4 Beta版时,我的应用程序无法在 Heroku 上启动,但在本地使用. 检查发现以下错误:bundle exec rails serverheroku logs -t

$ heroku[web.1]: State changed from crashed to starting
$ heroku[web.1]: Starting process with command `bin/rails server 
-p 33847 -e $RAILS_ENV`
$ app[web.1]: bash: bin/rails: No such file or directory
$ heroku[web.1]: Process exited with status 127
$ heroku[web.1]: State changed from starting to crashed
$ heroku[web.1]: Error R99 (Platform error) -> Failed to launch the 
dyno within 10 seconds
$ heroku[web.1]: Stopping process with SIGKILL

If I heroku run bashand check the bindirectory, I can see that there is nota railsexecutable:

如果我heroku run bash和检查bin目录,我可以看到,有没有一个rails可执行文件:

~$ ls bin
erb  gem  irb  node rdoc  ri  ruby  testrb

What have I done wrong? I followed the tutorial exactly.

我做错了什么?我完全按照教程操作。

采纳答案by Justin Garrick

After struggling with this for a bit, I noticed that my Rails 4 project had a /bindirectory, unlike some older Rails 3 projects I had cloned. /bincontains 3 files, bundle, rails, and rake, but these weren't making it to Heroku because I had binin my global .gitignorefile.

在为此苦苦挣扎了一段时间后,我注意到我的 Rails 4 项目有一个/bin目录,这与我克隆的一些较旧的 Rails 3 项目不同。 /bin包含 3 个文件,bundle, rails, 和rake,但这些文件没有进入 Heroku,因为bin我的全局.gitignore文件中有。

This is a pretty common ignore rule if you work with Git and other languages (Java, etc.), so to fix this:

如果您使用 Git 和其他语言(Java 等),这是一个非常常见的忽略规则,因此要解决此问题:

  1. Remove binfrom ~/.gitignore
  2. Run bundle install
  3. Commit your changes with git add .and git commit -m "Add bin back"
  4. Push your changes to Heroku with git push heroku master
  1. 删除bin~/.gitignore
  2. bundle install
  3. 使用git add .和提交您的更改git commit -m "Add bin back"
  4. 将您的更改推送到 Heroku git push heroku master

回答by JanuskaE

I had this problem also since I upgraded to rails 4.0.0

自从我升级到 rails 4.0.0 以来,我也遇到了这个问题

Run this command

运行这个命令

rake rails:update:bin

You can go here for more info https://devcenter.heroku.com/articles/rails4

你可以去这里了解更多信息 https://devcenter.heroku.com/articles/rails4

回答by Kirit Vaghela

Steps:

步骤

  1. bundle config --delete bin# Turn off Bundler's stub generator

  2. rake rails:update:bin# Use the new Rails 4 executables

  3. git add bin or git add bin -f# Add bin/ to source control

  4. git commit -a -m "you commit message"

  5. git push heroku master

  6. heroku open

  1. bundle config --delete bin# 关闭 Bundler 的存根生成器

  2. rake rails:update:bin# 使用新的 Rails 4 可执行文件

  3. git add bin or git add bin -f# 将 bin/ 添加到源代码管理

  4. git commit -a -m "you commit message"

  5. git push heroku master

  6. heroku open

回答by Ryan Taylor

I had this issue because the permissions on my ~/bindirectory were 644instead of 755. Running rake rails:update:binlocally (on Mac/*nix) and then pushing the changes fixed the problem.

我遇到这个问题是因为我的~/bin目录的权限644不是755. rake rails:update:bin在本地运行(在 Mac/*nix 上)然后推送更改修复了问题。

回答by TheSir

I had the very same problem that you did. The issue lied in the fact that the bin folder was never pushed to the heroku repository.

我遇到了和你一样的问题。问题在于 bin 文件夹从未被推送到 heroku 存储库。

I looked, I looked, and then I looked again, there was no rule in the .gitignore file for the bin/ folder...

我看了,我看了,然后我又看了看,.gitignore文件中没有bin/文件夹的规则......

Then, after a lot of pain and anguish, I realized that a couple of months before I had created a global .gitignore that would ignore all bin folders of all my repositories (why lord, why??).

然后,在经历了很多痛苦和痛苦之后,我意识到在我创建一个全局 .gitignore 之前的几个月,它会忽略我所有存储库的所有 bin 文件夹(为什么主啊,为什么?)。

I deleted the global .gitignore, and everything worked fine.

我删除了全局 .gitignore,一切正常。

回答by user2697012

We didn't have a myapp/bin directory in our rails 4 app, so we created one and then copied in the my app/script/rails file, plus the bundle and rake files from under rvm/ruby/bin and then added these to the repo for git and pushed it up to heroku and all was well.

我们的 rails 4 应用程序中没有 myapp/bin 目录,所以我们创建了一个,然后复制到我的 app/script/rails 文件中,加上 rvm/ruby/bin 下的 bundle 和 rake 文件,然后添加这些到 git 的 repo 并将其推送到 heroku,一切都很好。

回答by user4502882

I can confirm running rake rails:update:binworks, as said by @Ryan Taylor.

rake rails:update:bin正如@Ryan Taylor 所说,我可以确认正在运行的作品。

I think I had this problem because I originally created this Rails app on Windows. Running the command above on Linux solved for me.

我想我有这个问题,因为我最初在 Windows 上创建了这个 Rails 应用程序。在 Linux 上运行上面的命令为我解决了。

Also, on changing from Windows to Linux for development, it is a good idea to delete Gemfile.lockfile and run bundle installto generate it again without Windows specific gems listed there.

此外,在从 Windows 更改为 Linux 进行开发时,最好删除Gemfile.lock文件并运行bundle install以再次生成它,而无需在此处列出特定于 Windows 的 gem。