【问题标题】:Rails App works locally but not when deployed on HerokuRails 应用程序在本地工作,但在 Heroku 上部署时不能
【发布时间】:2016-07-03 22:49:25
【问题描述】:

我一直在关注 Michael Hartl 的 Rails 教程,并在第 5 章末尾尝试将我的应用程序部署到 Heroku。我完成了通常的步骤并确保应用程序在本地正确运行。

当我尝试打开应用程序时,我收到以下错误消息:

我们很抱歉,但出了点问题。查看日志以获取更多信息

我跑了

$heroku logs 

并得到以下内容

(master) $ heroku logs
2016-07-03T22:04:07.236612+00:00 app[web.1]:      5:   <%= stylesheet_link_tag        'application', media: 'all', 'data-turbolinks-track' => true %>
2016-07-03T22:04:07.236617+00:00 app[web.1]:     10: <body>
2016-07-03T22:04:07.236610+00:00 app[web.1]:   * "/app/app/views"
2016-07-03T22:04:07.236614+00:00 app[web.1]:      6:   <%=     javascript_include_tag 'application', 'data-turbolinks-track' => true %>
2016-07-03T22:04:07.236617+00:00 app[web.1]:      9: </head>
2016-07-03T22:04:07.236615+00:00 app[web.1]:      7:   <%= csrf_meta_tags %>
2016-07-03T22:04:07.236611+00:00 app[web.1]: ):
2016-07-03T22:04:07.236609+00:00 app[web.1]: ActionView::Template::Error       (Missing partial layouts/_shim with {:locale=>[:en], :formats=>[:html],     :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}.     Searched in:
2016-07-03T22:04:07.236620+00:00 app[web.1]: 
2016-07-03T22:04:07.236616+00:00 app[web.1]:      8:   <%= render     "layouts/shim" %>
2016-07-03T22:04:07.236618+00:00 app[web.1]:     11:   <%= render     'layouts/header' %>
2016-07-03T22:04:07.236619+00:00 app[web.1]:       app/views/layouts/application.html.erb:8:in     `_app_views_layouts_application_html_erb___1308690014084623887_70181780339020'
2016-07-03T22:04:07.236620+00:00 app[web.1]: 
2016-07-03T22:04:07.332794+00:00 heroku[router]: at=info method=GET     path="/favicon.ico" host=shielded-ocean-69345.herokuapp.com request_id=2b98b854-    e544-4a7a-b84c-17a9f523a784 fwd="96.250.10.105" dyno=web.1 connect=0ms service=5ms     status=304 bytes=48
2016-07-03T22:04:07.209635+00:00 heroku[router]: at=info method=GET path="/"     host=shielded-ocean-69345.herokuapp.com request_id=8414c14f-a2ea-4828-af90-    c94f46993f87 fwd="96.250.10.105" dyno=web.1 connect=0ms service=26ms status=500     bytes=1669
2016-07-03T22:08:00.831461+00:00 app[web.1]: Started GET "/" for 96.250.10.105     at 2016-07-03 22:08:00 +0000
2016-07-03T22:08:00.813784+00:00 heroku[router]: at=info method=GET path="/"     host=shielded-ocean-69345.herokuapp.com request_id=8b549d7c-caf4-4cee-81e7-    4df74e237ede fwd="96.250.10.105" dyno=web.1 connect=1ms service=26ms status=500     bytes=1669
2016-07-03T22:08:00.843662+00:00 app[web.1]:   * "/app/app/views"
2016-07-03T22:08:00.835335+00:00 app[web.1]: Processing by     StaticPagesController#home as HTML
2016-07-03T22:08:00.843652+00:00 app[web.1]: 
2016-07-03T22:08:00.842200+00:00 app[web.1]: Completed 500 Internal Server     Error in 7ms (ActiveRecord: 0.0ms)
2016-07-03T22:08:00.843665+00:00 app[web.1]:      5:   <%= stylesheet_link_tag        'application', media: 'all', 'data-turbolinks-track' => true %>
2016-07-03T22:08:00.843663+00:00 app[web.1]: ):
2016-07-03T22:08:00.838459+00:00 app[web.1]:   Rendered     static_pages/home.html.erb within layouts/application (1.0ms)
2016-07-03T22:08:00.843661+00:00 app[web.1]: ActionView::Template::Error     (Missing partial layouts/_shim with {:locale=>[:en], :formats=>[:html],     :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}.     Searched in:
2016-07-03T22:08:00.843667+00:00 app[web.1]:      7:   <%= csrf_meta_tags %>
2016-07-03T22:08:00.843669+00:00 app[web.1]:      8:   <%= render     "layouts/shim" %>
2016-07-03T22:08:00.843669+00:00 app[web.1]:      9: </head>
2016-07-03T22:08:00.843666+00:00 app[web.1]:      6:   <%=     javascript_include_tag 'application', 'data-turbolinks-track' => true %>
2016-07-03T22:08:00.843673+00:00 app[web.1]: 
2016-07-03T22:08:00.843672+00:00 app[web.1]:       app/views/layouts/application.html.erb:8:in     `_app_views_layouts_application_html_erb___1308690014084623887_70181780339020'
2016-07-03T22:08:00.843673+00:00 app[web.1]: 
2016-07-03T22:08:00.843670+00:00 app[web.1]:     10: <body>
2016-07-03T22:08:00.843671+00:00 app[web.1]:     11:   <%= render     'layouts/header' %>
2016-07-03T22:08:00.865455+00:00 heroku[router]: at=info method=GET      path="/favicon.ico" host=shielded-ocean-69345.herokuapp.com request_id=4d3005d1-     72e7-4f9d-bb0a-daef11fcb7d3 fwd="96.250.10.105" dyno=web.1 connect=0ms service=3ms      status=304 bytes=48
2016-07-03T22:12:19.033956+00:00 heroku[slug-compiler]: Slug compilation     started
2016-07-03T22:12:19.033964+00:00 heroku[slug-compiler]: Slug compilation     failed: failed to compile Ruby app
2016-07-03T22:13:49.911337+00:00 heroku[slug-compiler]: Slug compilation     failed: failed to compile Ruby app
2016-07-03T22:13:49.911326+00:00 heroku[slug-compiler]: Slug compilation     started
2016-07-03T22:14:53.615406+00:00 heroku[slug-compiler]: Slug compilation finished
2016-07-03T22:14:53.615398+00:00 heroku[slug-compiler]: Slug compilation started
2016-07-03T22:14:53.441497+00:00 heroku[api]: Release v9 created by     
2016-07-03T22:14:53.441423+00:00 heroku[api]: Deploy a287285 by 
2016-07-03T22:14:53.700320+00:00 heroku[web.1]: Restarting
2016-07-03T22:14:57.223797+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2016-07-03T22:14:57.232743+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 15046 -e production`
2016-07-03T22:14:58.065862+00:00 app[web.1]: - Gracefully stopping, waiting for requests to finish
2016-07-03T22:14:58.066171+00:00 app[web.1]: === puma shutdown: 2016-07-03 22:14:58 +0000 ===
2016-07-03T22:14:58.066206+00:00 app[web.1]: - Goodbye!
2016-07-03T22:14:58.066269+00:00 app[web.1]: Exiting
2016-07-03T22:14:59.302443+00:00 heroku[web.1]: Process exited with status 0
2016-07-03T22:15:01.107923+00:00 app[web.1]: => Booting Puma
2016-07-03T22:15:01.107985+00:00 app[web.1]: => Rails 4.2.2 application starting in production on http://0.0.0.0:15046
2016-07-03T22:15:01.107999+00:00 app[web.1]: => Ctrl-C to shutdown server
2016-07-03T22:15:01.107995+00:00 app[web.1]: => Run `rails server -h` for more startup options
2016-07-03T22:15:01.691975+00:00 app[web.1]: Puma starting in single mode...
2016-07-03T22:15:01.691991+00:00 app[web.1]: * Version 3.1.0 (ruby 2.2.4-p230), codename: El Niño Winter Wonderland
2016-07-03T22:15:01.691993+00:00 app[web.1]: * Min threads: 0, max threads: 16
2016-07-03T22:15:01.691994+00:00 app[web.1]: * Environment: production
2016-07-03T22:15:01.692097+00:00 app[web.1]: * Listening on  tcp://0.0.0.0:15046
2016-07-03T22:15:01.692333+00:00 app[web.1]: Use Ctrl-C to stop
2016-07-03T22:15:11.972090+00:00 app[web.1]: ActionView::Template::Error  (Missing partial layouts/_shim with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
2016-07-03T22:15:11.969112+00:00 app[web.1]:   Rendered static_pages/home.html.erb within layouts/application (1.5ms)
2016-07-03T22:15:11.971214+00:00 app[web.1]: Completed 500 Internal Server Error in 20ms (ActiveRecord: 0.0ms)
2016-07-03T22:15:11.911510+00:00 app[web.1]: Started GET "/" for 96.250.10.105 at 2016-07-03 22:15:11 +0000
2016-07-03T22:15:11.951234+00:00 app[web.1]: Processing by StaticPagesController#home as HTML
2016-07-03T22:15:11.972091+00:00 app[web.1]:   * "/app/app/views"
2016-07-03T22:15:11.972092+00:00 app[web.1]: ):
2016-07-03T22:15:11.972080+00:00 app[web.1]: 
2016-07-03T22:15:11.972093+00:00 app[web.1]:      5:   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
2016-07-03T22:15:11.972096+00:00 app[web.1]:      9: </head>
2016-07-03T22:15:11.972097+00:00 app[web.1]:     10: <body>
2016-07-03T22:15:11.972098+00:00 app[web.1]:   app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb___1593092074937796530_70210269730920'
2016-07-03T22:15:11.972099+00:00 app[web.1]: 
2016-07-03T22:15:11.972097+00:00 app[web.1]:     11:   <%= render 'layouts/header' %>
2016-07-03T22:15:11.972094+00:00 app[web.1]:      6:   <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
2016-07-03T22:15:11.972094+00:00 app[web.1]:      7:   <%= csrf_meta_tags %>
2016-07-03T22:15:11.972095+00:00 app[web.1]:      8:   <%= render "layouts/shim" %>
2016-07-03T22:15:11.972100+00:00 app[web.1]: 
2016-07-03T22:15:11.999714+00:00 heroku[router]: at=info method=GET path="/" host=shielded-ocean-69345.herokuapp.com request_id=43050116-0f99-423b-88f1-46d62700857f fwd="96.250.10.105" dyno=web.1 connect=0ms service=66ms status=500 bytes=1669
2016-07-03T22:15:12.052653+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=shielded-ocean-69345.herokuapp.com request_id=6ffdd04c-53c8-4383-a095-1d34f0ab155c fwd="96.250.10.105" dyno=web.1 connect=0ms service=2ms status=200 bytes=143
2016-07-03T22:16:19.702633+00:00 heroku[router]: at=info method=GET path="/" host=shielded-ocean-69345.herokuapp.com request_id=75bbacb3-3bd6-4d49-877f-1d8155eb5ba8 fwd="96.250.10.105" dyno=web.1 connect=1ms service=8ms status=500 bytes=1669
2016-07-03T22:16:19.696865+00:00 app[web.1]: Started GET "/" for 96.250.10.105     at 2016-07-03 22:16:19 +0000
2016-07-03T22:16:19.698826+00:00 app[web.1]: Processing by StaticPagesController#home as HTML
2016-07-03T22:16:19.700097+00:00 app[web.1]:   Rendered static_pages/home.html.erb within layouts/application (0.5ms)
2016-07-03T22:16:19.704512+00:00 app[web.1]: 
2016-07-03T22:16:19.704537+00:00 app[web.1]: ActionView::Template::Error (Missing partial layouts/_shim with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
2016-07-03T22:16:19.704540+00:00 app[web.1]:   * "/app/app/views"
2016-07-03T22:16:19.704540+00:00 app[web.1]: ):
2016-07-03T22:16:19.704541+00:00 app[web.1]:      5:   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
2016-07-03T22:16:19.701766+00:00 app[web.1]: Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.0ms)
2016-07-03T22:16:19.704543+00:00 app[web.1]:      7:   <%= csrf_meta_tags %>
2016-07-03T22:16:19.704542+00:00 app[web.1]:      6:   <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
2016-07-03T22:16:19.704545+00:00 app[web.1]:      9: </head>
2016-07-03T22:16:19.704544+00:00 app[web.1]:      8:   <%= render "layouts/shim" %>
2016-07-03T22:16:19.704545+00:00 app[web.1]:     10: <body>
2016-07-03T22:16:19.704546+00:00 app[web.1]:     11:   <%= render 'layouts/header' %>
2016-07-03T22:16:19.704548+00:00 app[web.1]: 
2016-07-03T22:16:19.704547+00:00 app[web.1]:   app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb___1593092074937796530_70210269730920'
2016-07-03T22:16:19.704548+00:00 app[web.1]: 
2016-07-03T22:16:19.758932+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=shielded-ocean-69345.herokuapp.com request_id=66c5443b-55f1-4d26-a231-f68b68fa32e0 fwd="96.250.10.105" dyno=web.1 connect=1ms service=2ms status=304 bytes=48

以下是我的application.html.erb文件的内容:

<!DOCTYPE html>
<html>
<head>
   <title><%= full_title(yield(:title)) %></title>
   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-   track' => true %>
   <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
   <%= csrf_meta_tags %>
   <%= render 'layouts/shim' %>
 </head>
 <body>
    <%= render 'layouts/header' %>
    <div class="container">
       <%= yield %>
       <%= render "layouts/footer" %>
    </div>
</body>
</html>

这里是被引用的 _shim 文件的内容:

<!--[if lt IE 9]>
    <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/r29/html15.min.js">
    </script>
<![endif]-->

我知道这很混乱,但是通过查看我不确定问题是什么。我希望更有经验的人能够为我指明正确的方向。

谢谢

【问题讨论】:

  • 你能添加你的application.html.erb文件吗?
  • 您应该将此添加到您的问题中。很抱歉,在 cmets 中读取文件很困难。

标签: ruby-on-rails ruby ruby-on-rails-4 heroku railstutorial.org


【解决方案1】:

这是错误:

ActionView::Template::Error (Missing partial layouts/_shim with {:locale=&gt;[:en], :formats=&gt;[:html], :variants=&gt;[], :handlers=&gt;[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:

您的主布局中缺少 shim 部分,创建主布局文件中调用的 shim 部分。

【讨论】:

    【解决方案2】:

    从日志看来,您丢失或放错了部分 shim,因为应用程序找不到它。在 Rails 中,partials 文件名以下划线开头:'_shim.html.erb'

    【讨论】:

      【解决方案3】:

      在部署到 heroku 之前,请更新您的 application.html.erb 文件,如下所示:

      <!DOCTYPE html>
      <html>
        <head>
          <title><%= full_title(yield(:title)) %></title>
          <%= render 'layouts/rails_default' %>
          <%= render 'layouts/shim' %>
        </head>
        <body>
          <%= render 'layouts/header' %>
          <div class="container">
            <%= yield %>
            <%= render 'layouts/footer' %>
          </div>
        </body>
      </html>
      

      【讨论】:

      • @john 如果这对您有帮助,请告诉我。
      • 感谢您的建议,但这仍然只在本地工作。知道它可能是什么吗?
      • 你迁移数据库了吗?
      • 是的,我在部署到 heroku 之前运行了 heroku run rake db:migrate。仍然没有运气。我有点困惑,因为我检查了所有语法并且我的所有文件似乎都被正确引用,所以我对可能出现的问题没有任何想法。
      • 你能分享你的github链接吗?我可以在我的系统中运行你的应用并检查
      【解决方案4】:

      虽然应用程序在本地运行(在 cloud9 上),但我在 Heroku 上收到了相同的错误消息。事实证明 Heroku 找不到该文件,因为我将 git 提交限制为 git commit -am 'message'。结果我没有提交任何新创建的文件(git commit -am 只提交修改过的文件,而不是新创建的文件)。尝试运行 git add . 然后提交。这应该让 Heroku 能够“看到”它丢失的文件。

      现在回答您的问题可能为时已晚,但希望这可以帮助寻找这个问题的答案的人 - 就像我一样。

      【讨论】:

        猜你喜欢
        • 2014-08-25
        • 2015-07-24
        • 1970-01-01
        • 1970-01-01
        • 2020-12-08
        • 1970-01-01
        • 2019-11-22
        • 2014-11-02
        • 2019-06-18
        相关资源
        最近更新 更多