繁体   English   中英

Heroku ActionView :: Template :: Error(nil:NilClass的未定义方法“名称”)

[英]Heroku ActionView::Template::Error (undefined method `name' for nil:NilClass)

第一次在这里发布。 尝试通过heroku打开网络应用程序时出现问题。 该应用程序是由Heroku成功构建的,但是当我尝试打开该应用程序时,出现以下错误:

2017-03-13T06:15:35.778714+00:00 app[web.1]: I, [2017-03-13T06:15:35.778662 #4]  INFO -- : [773bef2b-dfb4-45a9-a15f-0de210ab6964] Completed 500 Internal Server Error in 232ms (ActiveRecord: 18.7ms)
2017-03-13T06:15:35.779870+00:00 app[web.1]: F, [2017-03-13T06:15:35.779817 #4] FATAL -- : [773bef2b-dfb4-45a9-a15f-0de210ab6964]   
2017-03-13T06:15:35.780386+00:00 app[web.1]: F, [2017-03-13T06:15:35.779874 #4] FATAL -- : [773bef2b-dfb4-45a9-a15f-0de210ab6964] ActionView::Template::Error (undefined method `name' for nil:NilClass):
2017-03-13T06:15:35.780553+00:00 app[web.1]: F, [2017-03-13T06:15:35.780501 #4] FATAL -- : [773bef2b-dfb4-45a9-a15f-0de210ab6964]      7:       <tr>    
2017-03-13T06:15:35.780554+00:00 app[web.1]: [773bef2b-dfb4-45a9-a15f-0de210ab6964]      8:             <% row_cities.each do |city| %>     
2017-03-13T06:15:35.780555+00:00 app[web.1]: [773bef2b-dfb4-45a9-a15f-0de210ab6964]      9:                 <td>
2017-03-13T06:15:35.780556+00:00 app[web.1]: [773bef2b-dfb4-45a9-a15f-0de210ab6964]     10:                     <h3><%= city.name if city.name %></h3>
2017-03-13T06:15:35.780557+00:00 app[web.1]: [773bef2b-dfb4-45a9-a15f-0de210ab6964]     11:                     <p><%= city.country %></p>
2017-03-13T06:15:35.780558+00:00 app[web.1]: [773bef2b-dfb4-45a9-a15f-0de210ab6964]     12:                     <%= link_to "See More", city_path(city) %>
2017-03-13T06:15:35.780559+00:00 app[web.1]: [773bef2b-dfb4-45a9-a15f-0de210ab6964]     13:                 </td>
2017-03-13T06:15:35.780602+00:00 app[web.1]: F, [2017-03-13T06:15:35.780550 #4] FATAL -- : [773bef2b-dfb4-45a9-a15f-0de210ab6964]   
2017-03-13T06:15:35.780655+00:00 app[web.1]: F, [2017-03-13T06:15:35.780610 #4] FATAL -- : [773bef2b-dfb4-45a9-a15f-0de210ab6964] app/views/home_page/home.html.erb:10:in `block (2 levels) in _app_views_home_page_home_html_erb__1188228438750051727_70102451451540'

这是有问题的代码(视图:home.html.erb):

<div class="container-fluid text-center">
    <table>
    <% @cities.in_groups_of(3) do |row_cities| %>
        <tr>    
            <% row_cities.each do |city| %>     
                <td>
                    <h3><%= city.name %></h3>
                    <p><%= city.country %></p>
                    <%= link_to "See More", city_path(city) %>
                </td>
            <% end %>
        </tr>
    <% end %>
    </table>
</div>

以及它属于的控制器以防万一(home_page_controller.rb):

class HomePageController < ApplicationController
  def home
    @cities = City.all
  end
end

我已经在这个问题上待了两个星期了,并且看了其他与此类似的问题。 我尝试了所有答案都没有成功。 任何帮助表示赞赏。

问候,劳萨

PS这是它在我的本地主机服务器上的外观以及我希望它在heroku上的外观我希望它看起来如何-此处的图片

这是因为您使用的in_group_of没有选项。 用以下代码替换代码:

<div class="container-fluid text-center">
    <table>
    <% @cities.in_groups_of(3,false) do |row_cities| %>
        <tr>    
            <% row_cities.each_with_index do |city,index| %>
                <td>
                    <h3><%= city.name %></h3>
                    <p><%= city.country %></p>
                    <%= link_to "See More", city_path(city) %>
                </td>
            <% end %>
        </tr>
    <% end %>
    </table>
</div>

更多信息在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM