简体   繁体   中英

ActionView::Template::Error (undefined method `to_formatted_s' for nil:NilClass): on Heroku but Not Localhost

I have this page working properly on localhost but when I push to Heroku I'm getting the following error:

2016-09-04T04:35:37.745015+00:00 app[web.1]: Completed 500 Internal Server Error in 8ms (ActiveRecord: 2.6ms)
2016-09-04T04:35:37.745843+00:00 app[web.1]: 
2016-09-04T04:35:37.745844+00:00 app[web.1]: ActionView::Template::Error (undefined method `to_formatted_s' for nil:NilClass):
2016-09-04T04:35:37.745845+00:00 app[web.1]:     35:       <% @occasions.each do |o| %>
2016-09-04T04:35:37.745846+00:00 app[web.1]:     36:         <tr>
2016-09-04T04:35:37.745847+00:00 app[web.1]:     37:           <td>
2016-09-04T04:35:37.745848+00:00 app[web.1]:     38:             <%= o.date.to_formatted_s(:long) %>
2016-09-04T04:35:37.745848+00:00 app[web.1]:     39:           </td>
2016-09-04T04:35:37.745849+00:00 app[web.1]:     40:           <td>
2016-09-04T04:35:37.745850+00:00 app[web.1]:     41:             <%= link_to occasion_path(o), style: "color: black" do %>

The erb page it's on reads:

<%= image_tag 'memory_man.png', class: "slideRight", style: "width: 60%; right: 0; bottom: 0; position: absolute; visibility: hidden" %>

<div class="row" style="height: 125px"></div>

<% if flash[:notice] %>
  <div class="alert alert-success">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <%= flash[:notice] %>
  </div>
<% elsif flash.now[:alert] %>
  <div class="alert alert-danger">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <%= flash.now[:alert] %>
  </div>
<% elsif flash[:alert] %>
  <div class="alert alert-warning">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <%= flash[:alert] %>
  </div>
<% end %>

<div class="col-xs-12">
  <h1 class="text-center" style="margin-bottom: 15px">Your External Memory</h1>
  <% if @occasions.count == 0 %>
    <h4>If you don't trust us, we can't help you...</h4>
  <% else %>
    <table>
      <tr>
        <th>Date</th>
        <th>Thing to Remember</th>
        <th>Reapeats?</th>
        <th>Gift Needed?</th>
        <th>Email Reminders?</th>
      </tr>
      <% @occasions.each do |o| %>
        <tr>
          <td>
            <%= o.date.to_formatted_s(:long) %>
          </td>
          <td>
            <%= link_to occasion_path(o), style: "color: black" do %>
              <strong><%= o.name %></strong>
            <% end %>
            <%= link_to edit_occasion_path(o) do %>
              <span class="glyphicon glyphicon-edit" style="margin: 0" aria-hidden="true"></span>
            <% end %>
            <%= link_to occasion_path(o), method: :delete, data: { confirm: 'Are you sure?' } do %>
              <span class="glyphicon glyphicon-remove" style="margin: 0" aria-hidden="true"></span>
            <% end %>
          </td>
          <td>
            <%= o.repeating %>
          </td>
          <td>
            <% if o.gift %>
              Yup.
            <% else %>
              Nope!
            <% end %>
          </td>
          <td>
            <% if o.reminder %>
              Yes, fear not.
            <% else %>
              You're on your own.
            <% end %>
          </td>
        </tr>
      <% end %>
    </table>
  <% end %>
  <h4 class="text-center"><%= link_to "Add to My Internet-Braintrust", new_occasion_path, class: "hvr-grow btn btn-manly" %>
</div> <!-- container/columns -->

I've looked at some other SO posts with similar Heroku vs. localhost problems, but none of them have solved the issue. Can anyone offer any guidance on this situation?

looks like o.date is nil , you should find out which record contains a nil column date and assign a value. Or you can change your code:

o.date.try(:to_formatted_s, :long)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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