Skip to content

Instantly share code, notes, and snippets.

@teeparham
teeparham / _example_output.txt
Last active August 29, 2015 14:07 — forked from tomafro/example output
Find ActiveRecord columns without indexes
attachments: parent_id, asset_id
domain_names: organisation_id
event_memberships: user_id, event_id
events: editor_id
group_actions: user_id, group_id
groups: user_id
icons: parent_id
invitations: sender_id
legacy_actions: item_upon_id
news_items: author_id
@teeparham
teeparham / fixing_x000a.rb
Created April 24, 2012 22:13 — forked from andrewculver/fixing_x000a.rb
Temporary fix for the extra newline (
) Rails 3.2.3 + Haml are adding to the output of the text_area form helper.
module ActionView
module Helpers
module FormHelper
def text_area(object_name, method, options = {})
html = InstanceTag.new(object_name, method, self, options.delete(:object)).to_text_area_tag(options)
html.sub(/>\
/, '>').html_safe
end
end
end
end
@teeparham
teeparham / active_record_caching.rb
Created May 27, 2011 04:56 — forked from ahoward/active_record_caching.rb
simple active record caching
# for some reason active record doesn't include a simple way to serialize to
# cache. this simple trick will take you far
#
# usage:
#
# user = User.find(id)
#
# key = user.to_cache
#
# user = User.from_cache(key)
@teeparham
teeparham / migration_helper.rb
Created May 20, 2010 20:54 — forked from scottjacobsen/migration_helper.rb
Migrations Helper for foreign keys
module MigrationHelper
#options are:
# :pk_table_name
# :pk_column_name
# :cascade_delete
# :cascade_update
def add_fk(fk_table_name, fk_column_name, options={})
fk_table_name = fk_table_name.to_s
fk_column_name = fk_column_name.to_s
pk_table_name = options[:pk_table_name] || fk_column_name[0, fk_column_name.index("_id") || fk_column_name.length].pluralize