Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

heroku undefined method empty? when upgrading my app to ruby 2.0

I've recently upgraded my Heroku app from Cedar-10 to Cedar-14 with no problems (still using ruby 1.9.3). Then I tried upgrading my app to use ruby 2.0.0-p645 and push it to the heroku server. When I do this I can no longer access my app and I get the following error in the logs;

2015-07-09T12:27:37.480991+00:00 app[web.1]: 
2015-07-09T12:27:37.480996+00:00 app[web.1]: NoMethodError (undefined method `empty?' for nil:NilClass):
2015-07-09T12:27:37.480998+00:00 app[web.1]:   app/controllers/wines_controller.rb:18:in `index'
2015-07-09T12:27:37.480999+00:00 app[web.1]: 
2015-07-09T12:27:37.481001+00:00 app[web.1]: 
2015-07-09T12:27:37.481462+00:00 app[web.1]: Processing by WinesController#index as HTML
2015-07-09T12:27:37.481465+00:00 app[web.1]: Completed 500 Internal Server Error in 100.1ms

If I look at line 18 of the wines_controller I have the following;

respond_to do |format|
  format.html
  format.json {render json: @wines.as_json}
end

I thought it was something in my index.html, so I took that back to the this;

%h1 Wines

With just this one line in my index.html.haml it still had a problem.

If I try and access wines.json this works and gives me a list of my wines. Running on my development box using 2.0.0 works fine and all my tests pass.

Update: Add controller & more info on index.html

Here is my wines controller

  def index
    # Search via Ransack
    @q = current_user.wines.includes(:wine_rack).unconsumed.order("LOWER(winery)").search(params[:q])
    @wines = @q.result.page params[:page]
    @total = @q.result.sum(:qty)

    respond_to do |format|
      format.html
      format.json {render json: @wines.as_json}
    end
  end

In regards to my index.html.haml file I uploaded a version of my project which only included this one line;

%h1 Wines

There are no loops happening in the view and I still get the error.

Line 18 refers to the following line in my controller;

    respond_to do |format|
like image 358
map7 Avatar asked Jul 09 '15 12:07

map7


1 Answers

I found the answer. I had to upgrade my newrelic_rpm. It's the only thing I've changed and now it works.

-    newrelic_rpm (3.5.0)
+    newrelic_rpm (3.12.1.298)

I tested by loading up another instance of heroku and sending my app there a few times with various bits of the controller & view cut out, nothing changed until I remarked out newrelic_rpm gem and it started working. So I upgraded it instead of removing the gem and now it works.

The only reason I removed it was due to me looking for differences between development and production. It was marked as a production only gem in my Gemfile.

like image 192
map7 Avatar answered Oct 22 '22 00:10

map7