[英]How to override a file that is causing trouble in Ruby on Rails Spree Commerce App?
After having updated from Rails 3 to Rails 4 and installing the Bootstrap gem for Spree I get an error in app/views/spree/products/_image.html.erb
. 从Rails 3更新到Rails 4并安装Spree的Bootstrap gem后,我在
app/views/spree/products/_image.html.erb
。 The page looks as follows after I click on a image of a product on the main page: 在主页上单击产品图像后,该页面如下所示:
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
I know that this can be fixed by changing the file that is ruining it to only contain <%= product_image(@product, :itemprop => "image") %>
. 我知道可以通过更改破坏它的文件以仅包含
<%= product_image(@product, :itemprop => "image") %>
。 And I learned that I need to override files if I want them to change. 而且我了解到 ,如果我想更改文件,则需要覆盖文件。
So I want to change the code there so locally I added a file with the same path and name ( app/views/spree/products/_image.html.erb
) with the desired new code. 因此,我想在那里更改代码,因此在本地添加了具有相同路径和名称(
app/views/spree/products/_image.html.erb
)的文件,并带有所需的新代码。 Then I deployed it and when I ssh into the server I see the file. 然后我部署了它,当我将其SSH到服务器时,我看到了该文件。 But on the website I still get the same error.
但是在网站上我仍然遇到相同的错误。 Since trace of template inclusion said it came from
app/views/spree/products/show.html.erb
I also changed that file to it, but I still see the same code on the server. 由于模板包含的痕迹表示它来自
app/views/spree/products/show.html.erb
所以我也将该文件更改为它,但是我仍然在服务器上看到相同的代码。
How do I fix this? 我该如何解决?
Create this file in your project folder, then replace the contents with: 在您的项目文件夹中创建此文件 ,然后将内容替换为:
<%= product_image(@product, :itemprop => "image") %>
Or with this: 或与此:
<% if local_assigns[:image].present? && image %>
<%= image_tag image.attachment.url(:product), :itemprop => "image" %>
<% else %>
<%= product_image(@product, :itemprop => "image") %>
<% end %>
And btw, I don't see any need to overwrite app/views/spree/products/show.html.erb
if you're only doing it to get rid of the error. 顺便说一句,如果您只是为了消除错误,我认为不需要覆盖
app/views/spree/products/show.html.erb
。 The error is within the _image
partial, as stated in the GitHub issue. 如GitHub问题中所述,该错误位于
_image
部分中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.