Question

I'm having trouble to deploy my rails application to Heroku. I did it just as normally, but this time I got these errors on the console.

I wonder how they can appear, because I don't even have gsub! used in here.

In my normal production environment it worked just fine, so what did I forget to think about in this case?

Thanks for your help!

The Error prompts: (by the way, the database content isn't nil or something like that)

Started GET "/tournaments" for XXX at 2012-11-29 17:14:18 +0000
Processing by TournamentsController#index as HTML
  Rendered tournaments/index.html.erb within layouts/application (74.9ms)
Completed 500 Internal Server Error in 193ms

    31:     <td><%= raw tournament.address.split(", ").join("<br />") %></td>
    33:     <td><%= DateTime.parse(tournament.date).strftime("%H:%M") %></td>
ActionView::Template::Error (undefined method `gsub!' for 2012-12-08 15:00:00 UTC:Time):
    30:     <td><%= tournament.place %> von <%= tournament.participants %></td>
    35:     <td><%= link_to 'Show', tournament %></td>
  app/views/tournaments/index.html.erb:32:in `block in _app_views_tournaments_index_html_erb___1016767371206226983_23066580'
  app/views/tournaments/index.html.erb:26:in `each'
  app/views/tournaments/index.html.erb:26:in `_app_views_tournaments_index_html_erb___1016767371206226983_23066580'
    29:     <td><%= tournament.user.name %></td>

  app/controllers/tournaments_controller.rb:11:in `index'
    32:     <td><%= DateTime.parse(tournament.date).strftime("%d.%m.%Y") %></td>
    34:     <td><%= tournament.kind %></td>
Was it helpful?

Solution

It looks like the object returned by tournament.date is of type Time, where as DateTime.parse expects a string. The underlying implementation of the parse method does a gsub! on the argument passed. Hence the error.

You have two solutions :

  1. If you always get a Time object from tournament.date then you can use tournament.date.to_datetime (Although I don't think you actually need a DateTime object. You can use the Time object for the strftime)

  2. If you aren't guaranteed a Time object then pass the stringified object to parse like this DateTime.parse(tournament.date.to_s)

P.S : I do not know how this code worked for you on your local machine. Could be because of different ruby versions in the two setups. My answer is based on MRI 1.9.2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top