Skip to content

Instantly share code, notes, and snippets.

View tcocca's full-sized avatar

Tom Cocca tcocca

  • Boston Logic Technology Partners, Inc.
  • Boston, MA
View GitHub Profile
@tcocca
tcocca / FollowsController.rb
Created March 9, 2011 21:55
sample of how to use acts_as_follower with rails3 and ajax
class FollowsController < ApplicationController
def create
@user = User.find(params[:user_id])
current_user.follow(@user)
end
def destroy
@user = User.find(params[:user_id])
current_user.stop_following(@user)
@tcocca
tcocca / tomcat6
Created February 12, 2011 21:24
/etc/init.d/tomcat6
#!/bin/sh -e
# chkconfig: 345 99 1
# description: Tomcat6 service
# processname: java
# Get LSB functions
. /lib/lsb/init-functions
export JAVA_HOME=/usr
export TOMCAT_USER=solr
SELECT leads.id,
(SELECT COUNT(*) FROM searches WHERE lead_id = leads.id) AS searches_count,
(SELECT COUNT(*) FROM rental_searches WHERE lead_id = leads.id) AS rental_searches_count,
COALESCE((searches_count + rental_searches_count), 0) as total
FROM leads
WHERE leads.id = 35
# Unknown column 'searches_count' in 'field list'
class SearchReport < ActiveRecord::Base
belongs_to :user
belongs_to :report, :polymorphic => true
end
class User < ActiveRecord::Base
...
has_many :search_reports
class SearchDateRange < ActiveRecord::Base
validates_presence_of :name
validates_presence_of :sort_order
def range_start_end
time = Time.zone.now
case self.name
when 'Today'
[time.beginning_of_day, time.end_of_day]
#file: app/themes/blue/mixins/blue_users_controller_mixin.rb
module BlueUsersControllerMixin
def blue_show
#themed_show method here
end
end
# app/controllers/users_controller.rb
module ThemeMixin
=begin
# Rails only w/ alias_method_chain
def self.included(base)
base.alias_method_chain(:base_method, :override)
end
def base_method_with_override
"theme index"
attr_accessor :features_as_hash
def method_missing(method_name, *args, &block)
name = method_name.to_s
if self.respond_to?(name)
super
elsif features_hash.has_key?(name)
return features_hash[name]
else
logger.debug("Attribute #{name} on property #{self.id} does not exist")
map.resources :users do |user|
user.resources :daily_searches
end
map.namespace :admin do |admin|
admin.resources :leads do |lead|
lead.resources :daily_searches
end
end
@tcocca
tcocca / yo.rb
Created September 25, 2010 18:11 — forked from dpickett/yo.rb
def following_by_type(followable_type, options={})
follows = followable_type.constantize.
includes(:followings).
where(
"follows.follower_id = ? AND follows.follower_type = ? AND follows.followable_type = ? AND blocked = ?",
self.id, parent_class_name(self), followable_type, false
)
if options.has_key?(:limit)
return follows.limit(options[:limit])
end