views:

52

answers:

2

I have a Request model, which has a requesteeID field. When I'm running the site on my local computer, I can run this line of code:

a = Request.find_all_by_requesteeID(current_user.id)

and it works fine (note: I can't do current_user.requests because the models are joined by another field, requesterID). But when I run it on Heroku, it crashes, with the following error:

NoMethodError (undefined method `find_all_by_requesteeID' for #<Class:0x2ae0d29606d0>):

I have run heroku db:push, so the database is up to date. What could be causing this error on Heroku? Thanks for reading.

+3  A: 

If this is a new database column, even if you db:push or db:migrate, you may need to issue a heroku restart for Rails to realize you have a new database column.

Go to your application locally and do:

heroku restart

This will restart your application server(s) and reload everything.

Petros
agreed - this helps solve a lot of problems
stephenmurdoch
This worked! Thank-you!
ben
You are welcome ben.
Petros
+2  A: 

My tips for working with heroku -

  1. make sure you run thin on your localhost - there are certain instances where code will work in webrick but not in thin

  2. try setting up a production environment on your localhost and running your code in it - some code will work in development mode, but will fail in a production environment regardless of the hosting provider - if you run a production env on your localhost, you just might catch this bug

  3. rake db:push doesn't always do enough as someone else suggested - I often find myself running heroku rake db:drop followed by heroku rake db:migrate or heroku rake db:seed now that I have stopped using active_record - just try totally nuking your database and recreating from scratch - hint, this tip is a bit of a last resort

  4. a couple of days ago I installed mongoid-slug gem in an app and it was working perfectly in development but when I pushed to production it started causing all kinds of problems - the bug was being caused by the fact that I had no specified a gem version in my Gemfile so heroku was installing a slightly newer one - always specify the exact version that is working on your development machine - I'm gonna do that from now on

  5. same version of ruby in both environments

Hope you get it fixed - the main thing to try though, is to set up a production environment on your development machine and chances are that you'll find that the code fails there, just like it does on heroku

stephenmurdoch
I'm pretty new to RoR, so these tips are great. Thanks!
ben