Skip to content

Instantly share code, notes, and snippets.

View zorab47's full-sized avatar
⌨️

Charles Maresh zorab47

⌨️
View GitHub Profile
@zorab47
zorab47 / cache_arbre.rb
Last active May 13, 2023 14:17
Arbre content caching for ActiveAdmin
# Caches Arbre elements in the `Rails.cache`.
#
# Yielding the first time adds to the output buffer regardless of the
# returned value. A cache miss must be handled separately from a hit
# to avoid double rendering.
#
# Returns yielded Arbre on cache miss OR an HTML string wrapped in
# an text node on cache hit.
def cache_arbre(context, *args, &block)
if controller.perform_caching
@zorab47
zorab47 / active_record_eager_loading_issue_from_same_source.rb
Last active October 5, 2016 20:23
Reprodusable issue when eager loading relations from the same source
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", github: "rails/rails"
@zorab47
zorab47 / postgres_copy_csv.rb
Created December 6, 2017 01:09
Postgres CSV
module PostgresCopyCsv
extend ActiveSupport::Concern
module ClassMethods
# Performs a database query to copy results as CSV to an IO object.
#
# CSV is created directly in PostgreSQL with less overhead then written to
# the provided IO object.
#
# Example