Skip to content

Instantly share code, notes, and snippets.

View jocubeit's full-sized avatar
🎯
Focusing

Dom Jocubeit jocubeit

🎯
Focusing
View GitHub Profile
namespace :routes do
desc 'Print out all defined routes in match order, with names, per constraint class. Target specific constraint class with CONSTRAINT=x. Target specific controller with CONTROLLER=x.'
task constrained: :environment do
Rails.application.reload_routes!
constraints_routes = Hash.new
Rails.application.routes.routes.each do |route|
group = (route.app.class == ActionDispatch::Routing::Mapper::Constraints ? route.app.send( :constraints ).first.to_s : 'No constraint class')
constraints_routes[group] ||= []
@jocubeit
jocubeit / gist:1713910
Created January 31, 2012 23:45
Install Nokogiri on Mac OSX Lion including libiconv using Homebrew
# Install libxml2 using Homebrew
# If you don't have Homebrew, follow the instructions at:
# https://github.com/mxcl/homebrew/wiki/Installation
# -------------------------------------------------------
brew install libxml2
# Install libxslt from source code
# If you don't have wget, follow the instructions at:
# http://www.mactricksandtips.com/2008/07/installing-wget-on-your-mac-for-terminal.html
# Or use Homebrew:
@jocubeit
jocubeit / gist:1688707
Created January 27, 2012 13:13
Upgrade to Ruby 1.9.3, Rails 3.2.1 using RVM
# install Ruby 1.9.3 and Rails 3.2.1:
# -----------------------------------
rvm install ruby-1.9.3-p0
rvm use ruby-1.9.3-p0 --default
gem update --system
gem update rake
gem install bundler
gem install rails
# in your project directory:
@jocubeit
jocubeit / active_admin_filter_form_builder.rb
Created May 23, 2011 00:39
Remove 'Search ' in title for filtered columns in Active Admin
# lib/active_admin_filter_form_builder.rb
class ActiveAdmin::FilterFormBuilder
protected
def filter_string_input(method, options = {})
field_name = "#{method}_contains"
[ label(field_name, "#{method.to_s.titlecase}"),
@jocubeit
jocubeit / administration.rb
Created May 22, 2011 04:00
Build nested menu in Active Admin
# app/admin/administration.rb
ActiveAdmin.register Manager do
menu :parent => "Administration"
end
ActiveAdmin.register Backup do
menu :parent => "Administration"
end
@jocubeit
jocubeit / active_admin_views_pages_base.rb
Created May 22, 2011 03:57
Override footer content in Active Admin gem
# lib/active_admin_views_pages_base.rb
class ActiveAdmin::Views::Pages::Base < Arbre::HTML::Document
private
# Renders the content for the footer
def build_footer
div :id => "footer" do
para "Copyright &copy; #{Date.today.year.to_s} #{link_to('Example.com', 'http://example.com')}. Powered by #{link_to('Active Admin', 'http://www.activeadmin.info')} #{ActiveAdmin::VERSION}".html_safe
@jocubeit
jocubeit / category.rb
Created June 26, 2010 01:39
Dependent_collection_select in nested form
class Category < ActiveRecord::Base
has_many :products
attr_accessible :name, :type
CATEGORY_TYPES = %w[Product Sale]
validates_inclusion_of :type, :in => CATEGORY_TYPES
named_scope :of_products, :conditions => ["type = ?", "Product"]
named_scope :of_sales, :conditions => ["type = ?", "Sale"]
end
Processing SessionsController#create (for 127.0.0.1 at 2010-03-03 12:57:48) [POST]
Parameters: {"openid_url"=>"", "commit"=>"Login", "action"=>"create", "authenticity_token"=>"2SCDKJ4hIlBqDKc/XsRFT80WS2373+YozHhXmuZK5GI=", "controller"=>"sessions", "login"=>"admin", "password"=>"[FILTERED]"}
Preference Load (0.3ms) SELECT * FROM `preferences` 
Page Load (0.3ms) SELECT * FROM `pages` 
Tag Load (0.2ms) SELECT * FROM `tags` 
Category Load (0.1ms) SELECT * FROM `categories` 
Link Load (0.1ms) SELECT * FROM `links` 
Article Load (0.7ms) SELECT DISTINCT YEAR(created_at) AS `year`, MONTHNAME(created_at) AS `month_name`, MONTH(created_at) AS month, count(id) as articles FROM `articles` GROUP BY YEAR(created_at), MONTH(created_at) ORDER BY created_at DESC LIMIT 12
Menu Load (0.2ms) SELECT * FROM `menus` LIMIT 1
MenuItem Load (0