0

I see numerous posts regarding issues with deploying to Heroku, but I haven't been able to find the solution for my case. Any input would be much appreciated.

I have a blogging application that runs fine locally. However, I am returning "I'm sorry, but something went wrong" when I deploy to Heroku.

The gems I have are:

group :development do
  gem 'sqlite3', '1.3.5'
end

group :production do
  gem 'pg', '0.12.2'
end

The steps I've taken are:

git add.
git commit -am "latest update"
git push
git push heroku
rake db:migrate
heroku run rake db:migrate

My SQLite3 database is migrating fine, as I can find my latest blog entry (Blog.find(21)) through rails console. However, the data does not seem to be migrating to the Heroku database, as the Heroku console returns

"ActiveRecord::RecordNotFound: Couldn't find Blog with id=21."

Additionally, "heroku logs" finds:

Completed 500 Internal Server Error in 50ms
NoMethod Error (undefined method 'blogs' for nil:NilClass):
  app/controllers/static_pages_controller.rb:8:in 'home'

Does this mean there could be an issue in my static_pages_controller, or is it just returning an error because the database is not migrating correctly?

Below is my static_pages controller, which works fine on my local server.

class StaticPagesController < ApplicationController
  def home
    if signed_in?
      @blog = current_editor.blogs.build
    end

    @editor = Editor.first
    @blogs = @editor.blogs.paginate(page: params[:page])
  end
end

Note: I am using Editor.first above because I (ie. editor_id: 1) will be the only editor of my blog. I just created an Editor model to store the password_digest.

So, why isn't my application deploying on Heroku?

Any feedback would be appreciated. Also, please let me know if you need to see additional files, and I will attach.

Thanks so much!

mu is too short
  • 426,620
  • 70
  • 833
  • 800
umezo
  • 1,519
  • 1
  • 19
  • 33
  • Can you confirm you are pushing data from the correct local db? ie. Make sure you are NOT pushing like an empty production db or something up to Heroku? Maybe output from the data push would be useful? – Mario Zigliotto Jun 22 '12 at 05:36
  • Thanks SizzlePants. It seems that was the problem. However, I'm still not sure why I'd get "I'm sorry but something went wrong" message, even with an empty database. Shouldn't the Heroku deployment work (albeit with an empty site), as long as the columns are migrated correctly? – umezo Jun 22 '12 at 06:19
  • Heroku does handle that w/o any issue. I would expect that your views / code may make calls that assume an object's method should be available.... but actually are NOT due to nto having any data. An example would be if you had something you expected to be a string, then did like my_str.captialize ... if my_str was a nil object or not even a string... u would get an error. – Mario Zigliotto Jun 22 '12 at 06:30

1 Answers1

5

Running db:migrate only runs the database migrations, it won't copy any data from your development environment to Heroku. You should be using heroku db:push to push data from your local environment to Heroku:

Import: Push to Heroku

Use heroku db:push when you wish to transfer an existing database to Heroku. For example, you might want to import an SQLite database that you’ve been working with in local development or a MySQL database you have deployed on another host.

That sounds like what you want to do so try running heroku db:push.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • you are the man. i have no idea how you answer so many questions... So quickly. This is most likely the correct answer. – Mario Zigliotto Jun 22 '12 at 05:37
  • Thanks mu is too short. I ran gem install taps, then heroku db:push, but got an error . "HTTP CODE: 500. Taps Server Error: PGError: ERROR: time zone displacement out of range: "2012-06-06 12:00:00.000000+5894604000." I see that this pushes from config/database.yml. I just noticed my database.yml file says, "production: adapter:sqlite, database:db/production.sqlite3, pool:5, timeout:5000". I guess i should change these to postgresql? If so, do I need to change the pool and timeout figures as well? – umezo Jun 22 '12 at 06:12
  • @umezo: How are you getting a `+5894604000` timezone in SQLite? That doesn't make much sense. What do the timestamps look like if you access them through the `sqlite3` CLI tool? – mu is too short Jun 22 '12 at 06:53
  • I"m not sure how I ended up with this timezone... Time.now on the rails console returns => 2012-06-22 02:59:03 -400. This makes sense because I set the time to East Coast Time before. – umezo Jun 22 '12 at 06:59
  • @umezo: Have a look over here, looks like the same problem you're having: http://stackoverflow.com/questions/8151571/error-when-pushing-data-to-heroku-time-zone-displacement-out-of-range – mu is too short Jun 22 '12 at 07:04
  • I see the solution seems to be to use ruby 1.9.2 for the db:push to Heroku. I will update as soon as I figure out how to work with pik (I'm on Windows.). – umezo Jun 23 '12 at 05:13
  • @mu is too short: Thanks for the help. I was able to push my database up to Heroku with **heroku db:push** once I using pik to switch to ruby version 1.9.2, as well as install the taps gem. (I had to build a second app, as I'm still not sure what was causing the issue with my first one...) – umezo Jul 04 '12 at 01:16