Skip to content

Instantly share code, notes, and snippets.

View eliotsykes's full-sized avatar

Eliot Sykes eliotsykes

View GitHub Profile
@eliotsykes
eliotsykes / versioned_migrations.rb
Last active October 21, 2019 13:04
Versioned migrations support in Rails 4.2
# This file lives at config/initializers/versioned_migrations.rb
def supports_versioned_migrations?
Rails::VERSION::MAJOR >= 5
end
if supports_versioned_migrations?
ActiveSupport::Deprecation.warn(
"Versioned migrations are supported in your Rails version, you can delete file: #{__FILE__}"
)
return
@eliotsykes
eliotsykes / ar_base_configurations_usage.md
Last active August 15, 2018 05:56
ActiveRecord::Base.configurations usage

Usage of ActiveRecord::Base.configurations with surrounding lines to help answer https://twitter.com/eileencodes/status/1028624971675979777

Source: ~200 open source Rails apps and engines https://github.com/eliotsykes/real-world-rails

~/dev/real-world-rails (master)
$ ag --ruby -C 15 'ActiveRecord::Base.config'
apps/alaveteli/config/initializers/alaveteli.rb:60-require 'user_spam_scorer'
apps/alaveteli/config/initializers/alaveteli.rb:61-require 'alaveteli_rate_limiter'
apps/alaveteli/config/initializers/alaveteli.rb:62-require 'alaveteli_spam_term_checker'
@eliotsykes
eliotsykes / erb_parser.rb
Last active December 12, 2019 11:18
Parse ERB template ruby output expressions (using the temple gem)
# An example to extract the ruby output expressions from an ERB template using the temple gem:
#
# 1. Install 'temple' gem https://github.com/judofyr/temple
# 2. Require this erb_parser.rb file and run:
#
# ErbParser.call
#
# Dynamics will be:
# [[[:dynamic, " @page.title "],
# [:dynamic, " an_image "],
@eliotsykes
eliotsykes / jobs.rb
Last active December 21, 2020 15:58 — forked from webmat/dashboards.rb
Active Admin for DelayedJob
# Place this file in app/admin/jobs.rb
ActiveAdmin.register Delayed::Job, as: 'DelayedJob' do
# menu parent: 'Some Existing Menu' # optional
permit_params :priority, :queue, :run_at
actions :index, :show, :edit, :update, :destroy
config.batch_actions = true
index do
@eliotsykes
eliotsykes / active_job_deserializer_extension.rb
Created September 21, 2022 07:59
ActiveJob compatibility for Rails 5.2 -> 6.0 upgrade
# File: config/initializers/active_job_deserializer_extension.rb
return unless (VERSION::MAJOR == 5 && VERSION::MINOR == 2)
require "active_job/arguments"
module ActiveJobDeserializerExtension
# This copies the hash deserialization from activejob 6.0 so activejob 5.2 is forwards compatible, it can run jobs
# with hash args that were serialized by activejob 6.0. This allows Rails 5.2 and 6.0 to run within the same app
# during the upgrade period.
def deserialize_hash(serialized_hash)
@eliotsykes
eliotsykes / index.html.erb
Last active April 29, 2025 12:50
Testing Rails: defining temporary controller, view and route in feature spec
<% # This file lives at spec/features/views/index.html.erb %>
<h1>My Temporary Page</h1>