Skip to content

Instantly share code, notes, and snippets.

View 1990prashant's full-sized avatar

Prashant Kumar Mishra 1990prashant

View GitHub Profile
@1990prashant
1990prashant / application.js
Created March 16, 2016 06:21
To provide app token globally in javascript
$.ajaxSetup({
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
}
});
@1990prashant
1990prashant / users_controller.rb
Created March 2, 2016 08:24
To delete paperclip attachment
def remove_image
@user.image.clear #This is optional you can skip it
@user.image.destroy #This line delete image from paperclip
# Now you need to update image url because destroy is not remove url so you need to update image field
@user.update_attributes(image: nil)
end
#Note: You can directaly update your image field but it doesn't delete image from storage.
#Note1: Controller name may be changed according to your requirement.
@1990prashant
1990prashant / spree.rb
Last active January 28, 2016 12:01
To change spree currency from USD to INR. We need to change shipping method currency from admin shipping method from UI by log in as "admin" and then to change in the following file
config.currency = "INR"
#After that we need to update products currency accordingly.
@1990prashant
1990prashant / checkout_controller_decorator.rb
Created December 21, 2015 12:29
Skip delivery step but add default shipping for order in spree. Add the following methods in your order_decorator and checkout_controller_decorator
def before_delivery
if @order.needs_delivery?
return if params[:order].present?
packages = @order.shipments.map(&:to_package)
@differentiator = Spree::Stock::Differentiator.new(@order, packages)
else
#we select the shipping for the user
@order.select_default_shipping
@order.next #go to next step