开发者

Why does my RoR site work fine on my computer, but crash on Heroku?

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.开发者_C百科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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜