Hot questions for Using Spree in ruby on rails 4.2

Top 10 Ruby Open Source / Spree / ruby on rails 4.2

Question:

I am using Spree in my application and it's working pretty well except one issue that has got me thinking . On the product page , i have made products available according to the time of the day . But some of the products take values from the cache and based on time selected it puts in products that aren't supposed to be there . How can i stop caching on this single page of spree (I want it to be working on other pages though) .I have created an action for that page and put a before filter for it but it deletes cache from all the pages . Any inputs on the same would be highly welcome .


Answer:

Your best bet is probably to replace the view and remove the cache block:

https://github.com/spree/spree/blob/v3.0.0/frontend/app/views/spree/products/show.html.erb#L3

There are other solutions for disabling caching site wide, but nothing else that I know of for disabling specific caches that aren't terrible hacks.

Question:

Guys How to change the image size for a particular product on the Home page Like in default images size is small(100 x 100) I want to increase the image size but how i couldn't get it!! please Help me out guys!!!


Answer:

You can simply do this by download all the spree views and go to the provided link and give some class of any width and height.

https://github.com/spree/spree/blob/master/frontend/app/views/spree/shared/_products.html.erb

Thanks

Question:

I am upgrading my rails and spree to Rails 4.2 and Spree 3.1

I had overriden purchase! method in Payment model

This is how the method is in spree

module Spree
  class Payment < Spree::Base
    module Processing
      def purchase!
        started_processing!
        gateway_action(source, :purchase, :complete)
      end
    end
  end
end

This is how it was overridden in rails 3.2 (and it was working till now)

Spree::Payment::Processing.class_eval do
  def purchase!
    started_processing!
    if source.class == Spree::PurchaseOrder
      gateway_action(source, :authorize, :pend)
    else
      gateway_action(source, :purchase, :complete)
    end
  end
end

But now I am getting the following error with Rails 4.2 and Spree 3.1

/home/deepak/workspace/Project/app/models/spree/payment/processing_decorator.rb:2:in `<module:Spree>': superclass mismatch for class Payment (TypeError)
  from /home/deepak/workspace/Project/app/models/spree/payment/processing_decorator.rb:1:in `<top (required)>'
  from /home/deepak/.rvm/gems/ruby-2.3.1/gems/zeus-0.15.10/lib/zeus/load_tracking.rb:76:in `load'
  from /home/deepak/.rvm/gems/ruby-2.3.1/gems/zeus-0.15.10/lib/zeus/load_tracking.rb:76:in `load'
  from /home/deepak/.rvm/gems/ruby-2.3.1/gems/zeus-0.15.10/lib/zeus/load_tracking.rb:68:in `load'
  from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `block in load'
  from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
  from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `load'
  from /home/deepak/workspace/Project/config/application.rb:16:in `block (2 levels) in <class:Application>'
  from /home/deepak/workspace/Project/config/application.rb:15:in `glob'
  from /home/deepak/workspace/Project/config/application.rb:15:in `block in <class:Application>'

Answer:

# /initializers/spree_overrides.rb
module Spree
  class Payment < Spree::Base
    module Processing
      def purchase!
        started_processing!
        if source.class == Spree::PurchaseOrder
          gateway_action(source, :authorize, :pend)
        else
          gateway_action(source, :purchase, :complete)
        end
      end
    end
  end
end

Having it in initializer it will override the original method defined in Spree.