Skip to content

Instantly share code, notes, and snippets.

View johnmcaliley's full-sized avatar

John McAliley johnmcaliley

View GitHub Profile
article.impressions.create
article.impressions.create(:created_at => "2000-01-01")
article.impressions.create(:created_at => "2000-01-01")
article.impressions.create(:created_at => "2000-01-02")
impressions = article.impressions.select("count(*) as count, DATE_FORMAT(created_at,'%Y-%m-%d') as created_day").group("created_day")
impressions.each do |impression|
p "#{impression.created_day}: #{impression.count}"
end
@johnmcaliley
johnmcaliley / reopen_engine_model.rb
Created July 12, 2012 02:43
Reopen rails engine model in app
# Rails 3.2.6
# my_engine/app/models/user.rb
# Define class in engine
class User < ActiveRecord::Base
#methods here
end
# my_rails_app/app/models/user.rb
require "acts_as_charlie_sheen"
require "rails"
module ActsAsCharlieSheen
class Railtie < Rails::Railtie
initializer 'acts_as_charlie_sheen.ar_extensions' do |app|
ActiveRecord::Base.extend ActsAsCharlieSheen::Base
end
end
end
module ActsAsCharlieSheen
module Base
def acts_as_charlie_sheen
include InstanceMethods
end
module InstanceMethods
def sheenify!
["WINNING!",
"TIGER BLOOD!",
<p id="notice"><%= notice %></p>
<h1><%[email protected]! %></h1>
<%= link_to 'Edit', edit_person_path(@person) %> |
<%= link_to 'Back', people_path %>
class Person < ActiveRecord::Base
acts_as_charlie_sheen
end
gem 'acts_as_charlie_sheen', :git => 'git://github.com/your_username/acts_as_charlie_sheen.git'
require 'acts_as_charlie_sheen/base'
require 'acts_as_charlie_sheen/railtie'
Jeweler::Tasks.new do |gem|
gem.name = "acts_as_charlie_sheen"
gem.homepage = "http://github.com/johnmcaliley/acts_as_charlie_sheen"
gem.license = "MIT"
gem.summary = %Q{Make your classes act like Charlie Sheen}
gem.description = %Q{Adds functionality to classes to make them act like Charlie Sheen. WINNING!}
gem.email = "[email protected]"
gem.authors = ["John McAliley"]
end
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "acts_as_charlie_sheen"
gem.homepage = "http://github.com/johnmcaliley/acts_as_charlie_sheen"
gem.license = "MIT"
gem.summary = %Q{Make your classes act like Charlie Sheen}
gem.description = %Q{Adds functionality to classes to make them act like Charlie Sheen. WINNING!}
gem.email = "[email protected]"
gem.authors = ["John McAliley"]
end