Skip to content

Instantly share code, notes, and snippets.

View bbonamin's full-sized avatar
🕶️

Bruno Bonamin bbonamin

🕶️
View GitHub Profile
@bbonamin
bbonamin / event.rb
Created December 23, 2011 20:59
Globalize3 implementation on ActiveAdmin with nested forms
#app/models/event.rb
class Event < ActiveRecord::Base
translates :title, :description
has_many :event_translations
accepts_nested_attributes_for :event_translations, :allow_destroy => true
end
@bbonamin
bbonamin / how_to_run_rails_app.md
Created March 15, 2012 14:06
How to get a Rails app running on Windows
@bbonamin
bbonamin / galleries.rb
Created April 3, 2012 00:33
ActiveAdmin relationships and related models
# encoding: utf-8
ActiveAdmin.register Gallery do
menu :label => 'Galerías'
# => Índice
index do
column :name
column :description
column :date
default_actions
@bbonamin
bbonamin / ajaxify-html5.js
Created April 10, 2012 13:27 — forked from balupton/README.md
Ajaxify a Website with the HTML5 History API using History.js, jQuery and ScrollTo
// https://gist.github.com/854622
(function(window,undefined){
// Prepare our Variables
var
History = window.History,
$ = window.jQuery,
document = window.document;
// Check to see if History.js is enabled for our Browser
# Goal: Allow addition of instances to a collection in a factory-built object
# when those instances require references to the parent.
# Typically occurs in Rails when one model has_many instances of another
# See more at:
# http://stackoverflow.com/questions/2937326/populating-an-association-with-children-in-factory-girl
class Factory
def has_many(collection)
# after_build is where you add instances to the factory-built collection.
@bbonamin
bbonamin / capybara cheat sheet
Created April 23, 2012 14:30 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@bbonamin
bbonamin / will_paginate.rb
Created May 10, 2012 16:14 — forked from isaacbowen/will_paginate.rb
extends will_paginate to play well with Twitter's Bootstrap
# config/initializers/will_paginate.rb
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= BootstrapLinkRenderer
super.try :html_safe
end
class BootstrapLinkRenderer < LinkRenderer
@bbonamin
bbonamin / deploy.rb
Created May 16, 2012 16:15
Capistrano sample Rails 3.1
set :user, "username"
set :application, "app_name"
set :deploy_to, "/home/#{user}/rails_apps/#{application}"
set :rails_env, "production"
set :keep_releases, 3
set :scm, "git"
set :repository, "/path/to/application"
set :branch, "master"
@bbonamin
bbonamin / sh
Created May 22, 2012 12:36
Git colors
git config --global color.branch auto
git config --global color.diff auto
git config --global color.interactive auto
git config --global color.status auto
@bbonamin
bbonamin / log.log
Created May 22, 2012 18:37
Rails: Query comparison between a 3-level nested association.
Page Load (0.3ms) SELECT `pages`.* FROM `pages` 
ObjectMap Load (0.4ms) SELECT `object_maps`.* FROM `object_maps` WHERE `object_maps`.`page_id` = 1
ObjectProperty Load (0.3ms) SELECT `object_properties`.* FROM `object_properties` WHERE `object_properties`.`object_map_id` = 1
ObjectProperty Load (0.3ms) SELECT `object_properties`.* FROM `object_properties` WHERE `object_properties`.`object_map_id` = 2
ObjectProperty Load (0.3ms) SELECT `object_properties`.* FROM `object_properties` WHERE `object_properties`.`object_map_id` = 17
ObjectProperty Load (0.3ms) SELECT `object_properties`.* FROM `object_properties` WHERE `object_properties`.`object_map_id` = 18
ObjectMap Load (0.3ms) SELECT `object_maps`.* FROM `object_maps` WHERE `object_maps`.`page_id` = 3
ObjectProperty Load (0.2ms) SELECT `object_properties`.* FROM `object_properties` WHERE `object_propert