首先,这是edX Saas课程的作业问题,但我仍然在这里发帖,因为错误与我的作业没有直接关系。
我使用Ruby on Rails创建了一个application并将其托管在heroku上。 我的localhost上的应用程序显示所有电影的名称,但是当我在heroku上打开它时,没有可见的电影名称。
我使用heroku run rake:seed
来更新种子数据。这是我的种子文件:
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
当我尝试运行heroku run rails console
后跟Movie.all
时。我的数据库为:
[#<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">]
为什么标题,评级,描述等数据为零,而我可以在本地托管的应用程序中看到它们?
答案 0 :(得分:1)
尝试这样的事情:
m = Movie.new :title => 'Aladdin', :rating => 'G', :release_date => '25-Nov-1992'
m.save
然后尝试:
movies.each do |movie|
m = Movie.new(movie) #given that movie is in the format above.
m.save
end