This is a rough proof of concept.
There will be broken things.
Comments are welcome.
Installation
| # 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| |
| A comparison of Collection+JSON, HAL, JSON-LD and SIREN media types. | |
| Discussion at | |
| http://sookocheff.com/posts/2014-03-11-on-choosing-a-hypermedia-format/ |
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.
| module ActiveAdmin | |
| module Views | |
| class IndexAsTable < ActiveAdmin::Component | |
| include CustomHelper | |
| def column_select resource, attr, list | |
| val = resource.send(attr) | |
| html = _select list, val, { "attrs" => %{ | |
| data-path='#{resource.class.name.tableize}' |
NOTE: This post now lives (and kept up to date) on my blog: http://hakunin.com/rails3-load-paths
Do nothing. All files in this dir are eager loaded in production and lazy loaded in development by default.
| module Kaminari | |
| module PageScopeMethods | |
| def total_count | |
| @_hacked_total_count || (@_hacked_total_count = self.connection.execute("SELECT (reltuples)::integer FROM pg_class r WHERE relkind = 'r' AND relname ='#{table_name}'").first["reltuples"].to_i) | |
| end | |
| end | |
| end |
| # config/initializers/clear_logs.rb | |
| # This snippet simply clears your logs when they are too large. | |
| # Every time you start the rails environment it checks log sizes | |
| # and clears the logs for you if necessary. | |
| if Rails.env.development? | |
| MAX_LOG_SIZE = 10.megabytes | |
| logs = File.join(Rails.root, 'log', '*.log') |
| <!-- /app/views/admin/users/new_invitiations.html.erb --> | |
| <h2>Send invitation</h2> | |
| <%= form_for @user, :url => send_invitation_admin_users_path do |f| %> | |
| <table style='width: 50%'> | |
| <tr> | |
| <td><%= f.label :first_name %></td> | |
| <td><%= f.text_field :first_name %></td> |
| if has("autocmd") | |
| " remove trailing white spaces | |
| autocmd BufWritePre * :%s/\s\+$//e | |
| endif |