Helper method throws 'can't convert nil into String' in do loop on Heroku only

Go To StackoverFlow.com

0

Here is my code in my index view template:

<% @locations.each do |location| %>
  <tr>
    <td><%= link_to formatted_uwi(location.uwi), location_path(location) %></td>
    <td><%= location.name %></td>
    <td><%= location.created_at %></td>
    <td>
      <%= link_to 'Edit', edit_location_path(location), :class => 'btn btn-mini' %>
      <%= link_to 'Destroy', location_path(location), :method => :delete, :confirm => 'Are you sure?', :class => 'btn btn-mini btn-danger' %>
    </td>
  </tr>
<% end %>

It runs fine on my local dev system but fails on Heroku in pro & dev environments. I get:

"TypeError... can't convert nil into String"

formatted_uwi is a simple helper that formats the location.uwi input. If I call just 'location.uwi' or use an actual string in it's place it works fine and displays the raw location.uwi value so I know it's not a nil value. I even tried location.uwi.to_s.

Very bizarre. I can call this helper on the show, edit and other views and it works fine. It only fails in the do loop AND on Heroku.

2012-04-04 06:01
by Dan Tappin
Ok... it's getting wierder. @locations is a search result based on the users 'companyid' relation stored in a session (which I verified is working). If I switch to a user with no locations (via companyid) this code works because there are no locations to loop through. A user with locations fails on the nil.

What I havn't tried yet is pulling the helper out of the link_to to see if that is part of the problem - Dan Tappin 2012-04-04 16:55



0

Not sure what I did but I went back trough my helper to catch the nil and it seems to work now.

2012-04-05 06:11
by Dan Tappin
Ads