Ruby on rails 如何在Ruby中定义这个方法?

Ruby on rails 如何在Ruby中定义这个方法?,ruby-on-rails,ruby,heroku,Ruby On Rails,Ruby,Heroku,我真的坚持这个错误,希望有人帮助我解决它。 因此,我使用这个助手: module BooksHelper def image_from_amazon(amazon_id) image_tag "http://images.amazon.com/images/P/#{amazon_id}.01.ZTZZZZZZ.jpg" end end 查看文件 > <%= image_from_amazon(book.amazon_id) %> > 在我的本地机器

我真的坚持这个错误,希望有人帮助我解决它。 因此,我使用这个助手:

module BooksHelper
  def image_from_amazon(amazon_id)
        image_tag "http://images.amazon.com/images/P/#{amazon_id}.01.ZTZZZZZZ.jpg"
  end
end
查看文件

> <%= image_from_amazon(book.amazon_id) %>
>
在我的本地机器上,除了Heroku,一切都正常。日志:

> ActionView::Template::Error (undefined method `amazon_id' for #<Book:0x007f06994ea498>):
2015-08-18T16:28:19.320038+00:00 app[web.1]:      7: <% @books.each do |book| %>
2015-08-18T16:28:19.320040+00:00 app[web.1]:      8: <div class="book">
2015-08-18T16:28:19.320041+00:00 app[web.1]:      9:   <div class="cover">
2015-08-18T16:28:19.320042+00:00 app[web.1]:     10:     <%= image_from_amazon(book.amazon_id) %>
2015-08-18T16:28:19.320044+00:00 app[web.1]:     11:   </div>
2015-08-18T16:28:19.320045+00:00 app[web.1]:     12:   <div class="content">
2015-08-18T16:28:19.320047+00:00 app[web.1]:     13:     <h4 class="title"><%= link_to book.title, book %></h4>
2015-08-18T16:28:19.320048+00:00 app[web.1]:   app/views/books/index.html.erb:10:in `block in _app_views_books_index_html_erb__843408363563836431_69833158224880'
2015-08-18T16:28:19.320050+00:00 app[web.1]:   app/views/books/index.html.erb:7:in `_app_views_books_index_html_erb__843408363563836431_69833158224880'
>ActionView::Template::Error(未定义的#的“amazon_id”方法):
2015-08-18T16:28:19.320038+00:00应用程序[网站1]:7:
2015-08-18T16:28:19.320040+00:00应用程序[网站1]:8:
2015-08-18T16:28:19.320041+00:00应用程序[网站1]:9:
2015-08-18T16:28:19.320042+00:00应用程序[网站1]:10:
2015-08-18T16:28:19.320044+00:00应用程序[网站1]:11:
2015-08-18T16:28:19.320045+00:00应用程序[网站1]:12:
2015-08-18T16:28:19.320047+00:00应用程序[网站1]:13:
2015-08-18T16:28:19.320048+00:00 app[web.1]:app/views/books/index.html.erb:10:in ` block in `应用程序'视图'书籍'索引'html\u erb\u84340833563836431\u 69833158224880'
2015-08-18T16:28:19.320050+00:00 app[web.1]:app/views/books/index.html.erb:7:在`“应用程序-视图-书籍-索引”中
这一行是关键:

> ActionView::Template::Error (undefined method `amazon_id' for #<Book:0x007f06994ea498>):

books表是否有amazon id字段?你在heroku上运行迁移了吗?是的,我做了“heroku运行rake db:migrate”,但没有帮助。“heroku run rake db:setup”-帮助我。那为什么呢?我是否应该在每次部署后都创建一个新数据库?
puts "amazon_id: #{book.try(:amazon_id)}"