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>
It looks like the object returned by
tournament.dateis of typeTime, where asDateTime.parseexpects a string. The underlying implementation of theparsemethod does agsub!on the argument passed. Hence the error.You have two solutions :
If you always get a
Timeobject fromtournament.datethen you can usetournament.date.to_datetime(Although I don’t think you actually need aDateTimeobject. You can use theTimeobject for thestrftime)If you aren’t guaranteed a
Timeobject then pass the stringified object toparselike thisDateTime.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.