如何覆盖在Rauds Spree Commerce应用程序中造成Ruby中麻烦的文件



从Rails 3更新为Rails 4并安装Bootstrap Gem以进行狂欢,我在app/views/spree/products/_image.html.erb中会出现错误。在我单击主页上的产品图像之后,该页面如下:

 NameError in Spree::Products#show 
 Showing []/ruby/1.9.1/bundler
/gems/spree_bootstrap-a529d6bb6db0/app/views/spree/products/_image.html.erb where line 
#1 raised:
undefined local variable or method `image' for 
#<#<Class:0x000000070139c8>:0x000000068d7da8>
Extracted source (around line #1):
1
2
3
4
    <% if image %>
    <%= image_tag image.attachment.url(:product), :itemprop => "image" %>
    <% else %>
    <%= product_image(@product, :itemprop => "image") %>
Trace of template inclusion: []app/views/spree/products/show.html.erb
Rails.root: []/rails/releases/20140118194836

我知道,可以通过更改将其破坏该文件的文件仅包含<%= product_image(@product, :itemprop => "image") %>来解决。而且我了解到,如果我希望文件更改,我需要覆盖文件。

所以我想在那里更改代码,所以我在本地添加了一个带有所需新代码的路径和名称(app/views/spree/products/_image.html.erb)的文件。然后,我部署了它,当我进入服务器时,我会看到该文件。但是在网站上,我仍然会遇到相同的错误。由于包含模板包含的痕迹来自app/views/spree/products/show.html.erb,因此我也将该文件更改为它,但是我仍然在服务器上看到相同的代码。

我该如何修复?

在项目文件夹中创建此文件,然后用:

替换内容
<%= product_image(@product, :itemprop => "image") %>

或这样的:

<% if local_assigns[:image].present? && image %>
  <%= image_tag image.attachment.url(:product), :itemprop => "image" %>
<% else %>
  <%= product_image(@product, :itemprop => "image") %>
<% end %>

和顺便说一句,如果您只是为了摆脱错误,我认为不需要覆盖app/views/spree/products/show.html.erb。该错误在_image部分中,如GitHub问题所述。

最新更新