【问题标题】:Rails/Heroku Application Error - ActionView::Templete::ErrorRails/Heroku 应用程序错误 - ActionView::Templete::Error
【发布时间】:2023-03-06 22:16:01
【问题描述】:

当我将我的应用程序部署到 Heroku 时,我收到一个错误页面,上面写着“我们很抱歉,但出了点问题”。我将 puma 添加到我的 gem 文件中以便在那里运行服务器。不幸的是,这并没有解决问题。我在 Cloud 9 IDE 中工作。日志贴在下面。有人可以帮忙吗?

>     freshmurry:~/workspace (master) $ heroku logs --tail
>     WARNING: This is the legacy Heroku CLI with limited functionality. Please install the latest CLI.
>     WARNING: Installation instructions are at https://cli.heroku.com
>     2017-06-12T14:42:28.118206+00:00 app[web.1]: => Ctrl-C to shutdown server
>     2017-06-12T14:42:28.118197+00:00 app[web.1]: => Rails 4.2.6 application starting in production on http://0.0.0.0:7296
>     2017-06-12T14:42:28.118218+00:00 app[web.1]: [4] Puma starting in cluster mode...
>     2017-06-12T14:42:28.118219+00:00 app[web.1]: [4] * Version 3.9.1 (ruby 2.2.2-p95), codename: Private Caller
>     2017-06-12T14:42:28.118220+00:00 app[web.1]: [4] * Min threads: 1, max threads: 1
>     2017-06-12T14:42:28.118223+00:00 app[web.1]: [4] * Process workers: 2
>     2017-06-12T14:42:28.118221+00:00 app[web.1]: [4] * Environment: production
>     2017-06-12T14:42:28.118246+00:00 app[web.1]: [4] * Preloading application
>     2017-06-12T14:42:28.118403+00:00 app[web.1]: [4] * Listening on tcp://0.0.0.0:7296
>     2017-06-12T14:42:28.127987+00:00 app[web.1]: [4] - Worker 0 (pid: 7) booted, phase: 0
>     2017-06-12T14:42:28.118634+00:00 app[web.1]: [4] Use Ctrl-C to stop
>     2017-06-12T14:42:28.138176+00:00 app[web.1]: [4] - Worker 1 (pid: 12) booted, phase: 0
>     2017-06-12T14:42:28.468279+00:00 heroku[web.1]: State changed from starting to up
>     2017-06-12T14:43:21.618239+00:00 app[web.1]: Started GET "/" for 165.225.0.80 at 2017-06-12 14:43:21 +0000
>     2017-06-12T14:43:21.661531+00:00 app[web.1]: Processing by ProductsController#index as HTML
>     2017-06-12T14:43:21.676339+00:00 app[web.1]:   Product Load (1.5ms)  SELECT "products".* FROM "products"
>     2017-06-12T14:43:51.612669+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/"
> host=songchordz.herokuapp.com
> request_id=a209d2c5-1519-4829-b03f-8ad410a36cc7 fwd="165.225.0.80"
> dyno=web.1 connect=1ms service=30000ms status=503 bytes=0
> protocol=https
>     2017-06-12T14:43:51.738309+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=songchordz.herokuapp.com
> request_id=716c5e18-d421-49fd-9c3f-a1b406ef950d fwd="165.225.0.80"
> dyno=web.1 connect=1ms service=11ms status=200 bytes=188
> protocol=https
>     2017-06-12T14:44:19.815485+00:00 app[web.1]:   Rendered products/index.html.erb within layouts/application (58144.2ms)
>     2017-06-12T14:44:19.815964+00:00 app[web.1]: Completed 500 Internal Server Error in 58154ms (ActiveRecord: 7.1ms)
>     2017-06-12T14:44:19.819108+00:00 app[web.1]: 
>     2017-06-12T14:44:19.819110+00:00 app[web.1]: ActionView::Template::Error (Invalid CSS after "...   background: ":
> expected "{", was "url('/assets/si..."):
>     2017-06-12T14:44:19.819112+00:00 app[web.1]:     13:     <div class="product clearfix">
>     2017-06-12T14:44:19.819113+00:00 app[web.1]:     14:    <a href="<%= product_path(product)%>">
>     2017-06-12T14:44:19.819113+00:00 app[web.1]:     15:     <div class="product-image-container">
>     2017-06-12T14:44:19.819114+00:00 app[web.1]:     16:      <img src="<%= asset_path product.thumbnail_image_name %>" alt="<%=
> product.title %>"/>
>     2017-06-12T14:44:19.819115+00:00 app[web.1]:     17:      <span class="product-price">$<%= product.price %></span>
>     2017-06-12T14:44:19.819116+00:00 app[web.1]:     18:    </div>
>     2017-06-12T14:44:19.819117+00:00 app[web.1]:     19:    <p class="product-title"><%= product.title %></p></a>
>     2017-06-12T14:44:19.819118+00:00 app[web.1]:   app/views/products/index.html.erb:16:in `block in
> _app_views_products_index_html_erb__2962215687888486859_70188315801060'
>     2017-06-12T14:44:19.819118+00:00 app[web.1]:   app/views/products/index.html.erb:12:in
> `_app_views_products_index_html_erb__2962215687888486859_70188315801060'
>     2017-06-12T14:44:19.819120+00:00 app[web.1]: 
>     2017-06-12T14:44:19.819119+00:00 app[web.1]: 
>     2017-06-12T14:50:12.196944+00:00 app[web.1]: Started GET "/" for 165.225.0.83 at 2017-06-12 14:50:12 +0000
>     2017-06-12T14:50:12.246560+00:00 app[web.1]: Processing by ProductsController#index as HTML
>     2017-06-12T14:50:12.260255+00:00 app[web.1]:   Product Load (1.6ms)  SELECT "products".* FROM "products"
>     2017-06-12T14:50:18.705756+00:00 heroku[router]: at=info method=GET path="/" host=songchordz.herokuapp.com
> request_id=cb4de3d8-9abf-4c68-b7b3-08247b55c803 fwd="165.225.0.83"
> dyno=web.1 connect=2ms service=6512ms status=500 bytes=1714
> protocol=https
>     2017-06-12T14:50:18.758818+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=songchordz.herokuapp.com
> request_id=aa8706d9-9053-40ee-b586-c95a2324af8d fwd="165.225.0.83"
> dyno=web.1 connect=1ms service=2ms status=304 bytes=93 protocol=https
>     2017-06-12T14:50:18.706025+00:00 app[web.1]:     14:    <a href="<%= product_path(product)%>">
>     2017-06-12T14:50:18.704334+00:00 app[web.1]: Completed 500 Internal Server Error in 6458ms (ActiveRecord: 9.5ms)
>     2017-06-12T14:50:18.706028+00:00 app[web.1]:     18:    </div>
>     2017-06-12T14:50:18.706020+00:00 app[web.1]: 
>     2017-06-12T14:50:18.704044+00:00 app[web.1]:   Rendered products/index.html.erb within layouts/application (6448.0ms)
>     2017-06-12T14:50:18.706026+00:00 app[web.1]:     15:     <div class="product-image-container">
>     2017-06-12T14:50:18.706026+00:00 app[web.1]:     16:      <img src="<%= asset_path product.thumbnail_image_name %>" alt="<%=
> product.title %>"/>
>     2017-06-12T14:50:18.706024+00:00 app[web.1]:     13:     <div class="product clearfix">
>     2017-06-12T14:50:18.706027+00:00 app[web.1]:     17:      <span class="product-price">$<%= product.price %></span>
>     2017-06-12T14:50:18.706023+00:00 app[web.1]: ActionView::Template::Error (Invalid CSS after "...   background: ":
> expected "{", was "url('/assets/si..."):
>     2017-06-12T14:50:18.706029+00:00 app[web.1]:     19:    <p class="product-title"><%= product.title %></p></a>
>     2017-06-12T14:50:18.706030+00:00 app[web.1]:   app/views/products/index.html.erb:16:in `block in
> _app_views_products_index_html_erb__2962215687888486859_70188315745620'
>     2017-06-12T14:50:18.706031+00:00 app[web.1]:   app/views/products/index.html.erb:12:in
> `_app_views_products_index_html_erb__2962215687888486859_70188315745620'
>     2017-06-12T14:50:18.706031+00:00 app[web.1]: 
>     2017-06-12T14:50:18.706032+00:00 app[web.1]: 
>     2017-06-12T15:00:09.000000+00:00 app[api]: Build started by user user@yahoo.com
>     2017-06-12T15:00:26.386944+00:00 app[api]: Release v35 created by user user@yahoo.com
>     2017-06-12T15:00:26.386944+00:00 app[api]: Deploy bfdfd983 by user user@yahoo.com
>     2017-06-12T15:00:27.042332+00:00 heroku[web.1]: Restarting
>     2017-06-12T15:00:27.043183+00:00 heroku[web.1]: State changed from up to starting
>     2017-06-12T15:00:09.000000+00:00 app[api]: Build succeeded
>     2017-06-12T15:00:28.141928+00:00 heroku[web.1]: Stopping all processes with SIGTERM
>     2017-06-12T15:00:28.160932+00:00 app[web.1]: [4] - Gracefully shutting down workers...
>     2017-06-12T15:00:28.933799+00:00 app[web.1]: [4] === puma shutdown: 2017-06-12 15:00:28 +0000 ===
>     2017-06-12T15:00:28.933814+00:00 app[web.1]: [4] - Goodbye!
>     2017-06-12T15:00:28.933834+00:00 app[web.1]: Exiting
>     2017-06-12T15:00:29.287412+00:00 heroku[web.1]: Process exited with status 0
>     2017-06-12T15:00:33.688417+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 10601 -e production`
>     2017-06-12T15:00:42.161643+00:00 app[web.1]: => Booting Puma
>     2017-06-12T15:00:42.161681+00:00 app[web.1]: => Rails 4.2.6 application starting in production on http://0.0.0.0:10601
>     2017-06-12T15:00:42.161691+00:00 app[web.1]: => Run `rails server -h` for more startup options
>     2017-06-12T15:00:42.161692+00:00 app[web.1]: => Ctrl-C to shutdown server
>     2017-06-12T15:00:42.161754+00:00 app[web.1]: [4] Puma starting in cluster mode...
>     2017-06-12T15:00:42.161823+00:00 app[web.1]: [4] * Version 3.9.1 (ruby 2.2.2-p95), codename: Private Caller
>     2017-06-12T15:00:42.161864+00:00 app[web.1]: [4] * Min threads: 1, max threads: 1
>     2017-06-12T15:00:42.161937+00:00 app[web.1]: [4] * Environment: production
>     2017-06-12T15:00:42.161980+00:00 app[web.1]: [4] * Process workers: 2
>     2017-06-12T15:00:42.162025+00:00 app[web.1]: [4] * Preloading application
>     2017-06-12T15:00:42.162303+00:00 app[web.1]: [4] * Listening on tcp://0.0.0.0:10601
>     2017-06-12T15:00:42.162802+00:00 app[web.1]: [4] Use Ctrl-C to stop
>     2017-06-12T15:00:42.175712+00:00 app[web.1]: [4] - Worker 0 (pid: 7) booted, phase: 0
>     2017-06-12T15:00:42.178719+00:00 app[web.1]: [4] - Worker 1 (pid: 9) booted, phase: 0
>     2017-06-12T15:00:42.741234+00:00 heroku[web.1]: State changed from starting to up
>     2017-06-12T15:03:34.480518+00:00 app[web.1]: Started GET "/" for 165.225.0.80 at 2017-06-12 15:03:34 +0000
>     2017-06-12T15:03:34.535895+00:00 app[web.1]: Processing by ProductsController#index as HTML
>     2017-06-12T15:03:34.556604+00:00 app[web.1]:   Product Load (1.7ms)  SELECT "products".* FROM "products"
>     2017-06-12T15:04:04.458759+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/"
> host=songchordz.herokuapp.com
> request_id=99da6242-45eb-4039-b35c-770b1594beec fwd="165.225.0.80"
> dyno=web.1 connect=0ms service=30001ms status=503 bytes=0
> protocol=https
>     2017-06-12T15:04:34.582637+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/favicon.ico"
> host=songchordz.herokuapp.com
> request_id=734596fb-2cb9-4bd4-9cc5-4fc85c747ed5 fwd="165.225.0.80"
> dyno=web.1 connect=0ms service=30001ms status=503 bytes=0
> protocol=https
>     2017-06-12T15:04:49.462061+00:00 app[web.1]:   Rendered products/index.html.erb within layouts/application (74910.8ms)
>     2017-06-12T15:04:49.467310+00:00 app[web.1]: Completed 500 Internal Server Error in 74931ms (ActiveRecord: 6.5ms)
>     2017-06-12T15:04:49.470398+00:00 app[web.1]: 
>     2017-06-12T15:04:49.470410+00:00 app[web.1]: ActionView::Template::Error (Invalid CSS after "...   background: ":
> expected "{", was "url('/assets/si..."):
>     2017-06-12T15:04:49.470412+00:00 app[web.1]:     13:     <div class="product clearfix">
>     2017-06-12T15:04:49.470414+00:00 app[web.1]:     14:    <a href="<%= product_path(product)%>">
>     2017-06-12T15:04:49.470415+00:00 app[web.1]:     15:     <div class="product-image-container">
>     2017-06-12T15:04:49.470415+00:00 app[web.1]:     16:      <img src="<%= asset_path product.thumbnail_image_name %>" alt="<%=
> product.title %>"/>
>     2017-06-12T15:04:49.470416+00:00 app[web.1]:     17:      <span class="product-price">$<%= product.price %></span>
>     2017-06-12T15:04:49.470418+00:00 app[web.1]:     18:    </div>
>     2017-06-12T15:04:49.470419+00:00 app[web.1]:     19:    <p class="product-title"><%= product.title %></p></a>
>     2017-06-12T15:04:49.470420+00:00 app[web.1]:   app/views/products/index.html.erb:16:in `block in
> _app_views_products_index_html_erb__4490733878524225278_70102825789420'
>     2017-06-12T15:04:49.470421+00:00 app[web.1]:   app/views/products/index.html.erb:12:in
> `_app_views_products_index_html_erb__4490733878524225278_70102825789420'
>     2017-06-12T15:04:49.470421+00:00 app[web.1]: 
>     2017-06-12T15:04:49.470422+00:00 app[web.1]:

【问题讨论】:

  • 我确实看到了这个错误:2017-06-12T15:04:49.470410+00:00 app[web.1]: ActionView::Template::Error (Invalid CSS after "... background: ": &gt; expected "{", was "url('/assets/si..."):
  • 尝试运行heroku run rake assets:precompile 看看是否显示您的资产有错误。
  • 这也有帮助...问题的根源在于我的 application.css.scss 文件。我不得不删除“css”扩展。

标签: ruby-on-rails heroku actionview


【解决方案1】:

任何时候看到这样的错误:

2017-06-12T15:04:49.470410+00:00 app[web.1]: ActionView::Template::Error (Invalid CSS after "... background: ": > expected "{", was "url('/assets/si..."):

它作为一个线索。线索在术语 ActionView::Template 中。了解 Ruby on Rails 框架的工作原理对于了解发生了什么很重要。以下是关于 ActionView 意义的指南:

http://guides.rubyonrails.org/action_view_overview.html

Rails 使用这个名为 ActionView 的工具,ActionView 的作用是协助将控制器映射到视图,但不要相信我的话,只需阅读我在上面发布的文档,尤其是这一部分:

对于每个控制器,在 app/views 目录中都有一个关联目录,其中包含构成与该控制器关联的视图的模板文件。这些文件用于显示每个控制器操作产生的视图。

那我为什么要发布这个?好吧,如果您知道 ActionView 将控制器映射到视图,然后您还看到了术语模板,那么它可以作为一个重要线索,表明问题出在您的模型-视图-控制器应用程序的视图中。用这种方式隔离这个框架的问题是不是很棒?

然后那条错误信息中还有一条线索,Invalid CSS after...

我认为这是最大和最明显的线索。您有无效的 CSS 并且它没有正确呈现在您的视图中,这就是模板和 ActionView 出现在错误场景中的原因。

我知道你最终想通了,但答案还在于你如何解决问题,而不仅仅是解决问题。最终,如果您不知道 Ruby on Rails MVC 框架及其所有工具的工作原理,您将遇到另一个无法破译的错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 1970-01-01
    • 2016-04-01
    • 2014-11-19
    • 2014-03-12
    • 2015-10-31
    • 2013-05-15
    相关资源
    最近更新 更多