简体   繁体   中英

Error in uploading seed data on heroku

First of all, this is a homework question for edX Saas course but I am still posting it here as the error is not directly related to my homework.

I have made an application using Ruby on Rails and hosted it on heroku. The application on my localhost is showing the names of all the movies but when I open it on heroku, there's no movie name visible.

I used heroku run rake:seed to update my seed data. And here is my seed file:

if count = Movie.count  > 0
Movie.delete_all
puts "deleting #{count} old rows of seed data"
end

movies = [{:title => 'Aladdin', :rating => 'G', :release_date => '25-Nov-1992'},
        {:title => 'The Terminator', :rating => 'R', :release_date => '26-Oct-1984'},
        {:title => 'When Harry Met Sally', :rating => 'R', :release_date => '21-Jul-1989'},
      {:title => 'The Help', :rating => 'PG-13', :release_date => '10-Aug-2011'},
      {:title => 'Chocolat', :rating => 'PG-13', :release_date => '5-Jan-2001'},
      {:title => 'Amelie', :rating => 'R', :release_date => '25-Apr-2001'},
      {:title => '2001: A Space Odyssey', :rating => 'G', :release_date => '6-Apr-1968'},
      {:title => 'The Incredibles', :rating => 'PG', :release_date => '5-Nov-2004'},
      {:title => 'Raiders of the Lost Ark', :rating => 'PG', :release_date => '12-Jun-1981'},
      {:title => 'Chicken Run', :rating => 'G', :release_date => '21-Jun-2000'},
     ]

movies.each do |movie|
 Movie.create!(movie)
end

When I tried running heroku run rails console followed by Movie.all . I got my database as:

[#<Movie id: 53, title: nil, rating: nil, description: nil, release_date: nil, created_at: "2014-11-30 18:29:18", updated_at: "2014-11-30 18:29:18">, #<Movie id: 54, title: nil, rating: nil, description: nil, release_date: nil, created_at: "2014-11-30 18:29:18", updated_at: "2014-11-30 18:29:18">, #<Movie id: 55, title: nil, rating: nil, description: nil, release_date: nil, created_at: "2014-11-30 18:29:18", updated_at: "2014-11-30 18:29:18">, #<Movie id: 56, title: nil, rating: nil, description: nil, release_date: nil, created_at: "2014-11-30 18:29:18", updated_at: "2014-11-30 18:29:18">, #<Movie id: 57, title: nil, rating: nil, description: nil, release_date: nil, created_at: "2014-11-30 18:29:18", updated_at: "2014-11-30 18:29:18">, #<Movie id: 58, title: nil, rating: nil, description: nil, release_date: nil, created_at: "2014-11-30 18:29:18", updated_at: "2014-11-30 18:29:18">, #<Movie id: 59, title: nil, rating: nil, description: nil, release_date: nil, created_at: "2014-11-30 18:29:18", updated_at: "2014-11-30 18:29:18">, #<Movie id: 60, title: nil, rating: nil, description: nil, release_date: nil, created_at: "2014-11-30 18:29:18", updated_at: "2014-11-30 18:29:18">, #<Movie id: 61, title: nil, rating: nil, description: nil, release_date: nil, created_at: "2014-11-30 18:29:18", updated_at: "2014-11-30 18:29:18">, #<Movie id: 62, title: nil, rating: nil, description: nil, release_date: nil, created_at: "2014-11-30 18:29:18", updated_at: "2014-11-30 18:29:18">]

Why is the data like title, rating, description etc nil, while I can see them in my locally hosted application?

Try something like this:

m = Movie.new :title => 'Aladdin', :rating => 'G', :release_date => '25-Nov-1992'
m.save

Then try:

movies.each do |movie|
 m = Movie.new(movie) #given that movie is in the format above. 
 m.save
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM