Skip to content

Instantly share code, notes, and snippets.

View 1990prashant's full-sized avatar

Prashant Kumar Mishra 1990prashant

View GitHub Profile
@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
@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 / 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 / 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 / application.js
Created March 16, 2016 06:23
To write prototype js
var mashkar = {
init: function() {
this.calculateTotalPrice();
},
calculateTotalPrice: function() {
$(document).on("change", '.price-field', function() {
var variantRow = $(this).closest(".variant-row");
var sellerPrice = parseFloat($(this).val());
@1990prashant
1990prashant / GemFile
Last active August 14, 2018 09:00
Noty in rails
#Add noty gem
gem 'noty-rails'
# Run bundle command from your terminal
@1990prashant
1990prashant / application.js
Created March 16, 2016 06:29
To call noty within javascript
noty({text: "Please select an image", type: "error"});
#type may be warning, notice etc.
@1990prashant
1990prashant / controller.rb
Created March 16, 2016 06:47
Render a page through controller
def comment
@comment = Spree::Post.new(post_params)
@comment.attributes = {user_id: current_spree_user.id}
if @comment.save
render json: {
success: true,
comment: render_to_string((@comment.parent_id.blank? ? 'spree/shared/_previous_comments' : 'spree/shared/_comment_line_item'), :layout => false, :locals => { :comment => @comment })
}
else
render json: {
@1990prashant
1990prashant / gist:5d743dfb0549b6a186ec
Created March 17, 2016 07:57
How to check how many cases are covered in a rails test case
Run the below comman in terminal
xdg-open .
A file explorer is opened
then run index.html
@1990prashant
1990prashant / gemfile
Created March 25, 2016 07:27
Configuring puma for rails server
gem 'puma'