问题
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
. 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") %>. 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. Then I deployed it and when I ssh into the server I see the file. 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.
How do I fix this?
回答1:
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. The error is within the _image
partial, as stated in the GitHub issue.
来源:https://stackoverflow.com/questions/21209138/how-to-override-a-file-that-is-causing-trouble-in-ruby-on-rails-spree-commerce-a