簡體   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