Skip to content

Instantly share code, notes, and snippets.

@TylerRick
TylerRick / content_for_inside_cache.rb
Last active June 11, 2020 05:37 — forked from stackng/rails content_for caching
Add ability to use content_for within a fragment cache block (Rails 5.2)
# config/initializers/content_for_inside_cache.rb
module AbstractController
class Base
attr_internal :cached_content_for
end
module Caching
# actionpack/lib/action_controller/caching/fragments.rb
module Fragments
@TylerRick
TylerRick / detailed_hash_diff.rb
Last active July 22, 2022 18:25 — forked from fabriciofreitag/detailed_hash_diff.rb
Custom RSPec matcher for detailed hash compasion and diff
require 'facets/hash/recurse'
# Usage:
# expect(actual).to match_hash(expected)
#
RSpec::Matchers.define :match_hash do |expected|
match do |actual|
# Sort hashes before comparing so that the diff only shows actual changes between keys and
# values.
actual = actual.recurse {|h| h.sort_by {|k,v| k.to_s }.to_h }
@TylerRick
TylerRick / .gitignore
Created January 19, 2018 18:12 — forked from ZJONSSON/force_labels.js
Automatic floating labels using d3 force-layout
d3-force-labels.js
@TylerRick
TylerRick / main.rb
Created January 16, 2018 19:04 — forked from coorasse/main.rb
CanCanCan Issue
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '5.1.4'
namespace :spree do
desc "Export Products to CSV File"
task :export_products => :environment do
require 'csv'
products = Product.where(:deleted_at => nil).all
puts "Exporting to #{RAILS_ROOT}/products.csv"
CSV.open("#{RAILS_ROOT}/products.csv", "w") do |csv|
csv << [