Skip to content

Instantly share code, notes, and snippets.

# This file extends and overrides parts of the ActiveAdmin DSL and internals
# in order to provide support for automatically displaying and editing images,
# which in our infrastructure are stored as URLs whose column names end in "img".
# Since this file will be reloaded frequently in the development environment,
# all operations done at load time (class_eval's, etc.) MUST be idempotent.
ActiveAdmin::Views::TableFor.class_eval do
def img_column(col_sym=:img, title="Image")
column title, sortable: false do |obj|
module ActiveAdminHelper
def admin_arbre_context
@admin_arbre_context ||= Arbre::Context.new(assigns, self)
end
def default_renderer
case controller.send(:resource_class).name
when "ActiveAdmin::Page"
"page"

Saving ActiveAdmin filters between requests

This shows one technique for preserving filters on index pages for ActiveAdmin resources, without having to patch the ActiveAdmin core.

It restores any previously-used filters whenever the index page is rendered for a resource, unless the current request is an actual application of new filters. It also properly handles the clear-filters button (via a synchronous Ajax request that happens immediately before the normal filter form processing).

Yes, it's a bit of a hack, but it has worked well for me so far.

Usage

module DefaultValues
def has_default_values(default_values = {})
class_attribute :default_values
self.default_values = default_values
after_initialize :assign_default_values
include InstanceMethods
@Fivell
Fivell / pg_sp.sql
Last active August 29, 2015 13:57
pg sp exmple
# psql -U postgres
psql (9.3.4)
Type "help" for help.
postgres=# CREATE FUNCTION insert_city(character varying)
postgres-# RETURNS void AS
postgres-# $BODY$
postgres$# BEGIN
postgres$# INSERT INTO city("name") VALUES($1);
postgres$# END
@Fivell
Fivell / controller_exception_notification
Created January 14, 2014 14:31
exeption notification
rescue_from StandardError, :with => :notify_exception
def notify_exception(e)
ActionMailer::Base.mail(:from => "application@email.com", :to => "developer@email.com",
:subject => e.message,
:body => [e.backtrace.join("\n"), self.request.inspect].join("\n\n\n")).deliver
raise e
end
# db/migrations/20120118012543_create_site_configuration.rb
class CreateSiteConfigurations < ActiveRecord::Migration
def change
create_table :site_configurations do |t|
t.string :key
t.text :value
t.string :form_type
t.string :form_collection_command
module ActiveAdmin
module Reports
module DSL
def enable_reports
action_item only: :index do
link_to("Download", {action: :report, params: params}, {method: :post, data: { confirm: "Are you sure you want to generate this report?"}})
end
collection_action :report, method: :post do
# if you want to monkey patch every controller, put this in initializers/active_admin.rb
ActiveAdmin::ResourceController.class_eval do
include ActiveAdmin::CSVStream
end
require 'rubygems'
require 'rubygems/package'
require 'zlib'
require 'fileutils'
module Util
module Tar
# Creates a tar file in memory recursively
# from the given path.
#