1
我真的堅持這個錯誤,並希望有人幫我解決它。 所以,我用這個幫手:如何在Ruby中定義此方法?
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'
書的表是否有亞馬遜ID字段?你有沒有在heroku上進行遷移? – coderhs
是的,我做了「heroku運行耙db:遷移」,但它並沒有幫助。 「heroku運行耙db:設置」 - 幫助我。所以爲什麼?每次部署後我應該創建一個新的數據庫嗎? – Hola