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
namespace :associations do
desc "display a models associations"
task :model => :environment do
puts "\n"
ENV['model'].constantize.reflect_on_all_associations.each do |association|
assoc_str = "#{association.macro} :#{association.name}"
unless association.options.blank?
association.options.each do |key,val|
assoc_str += ", :#{key} => #{val}" unless val.blank? || key == :extend
<%= select_tag "searches", options_for_select([["Select a Search",""],["Tom",1],["Chris",2]]), :onchange => "search_redirect(this);" %>
<script type="text/javascript" charset="utf-8">
function search_redirect(field) {
if (field.value != "") {
window.location = "http://localhost:3000/searches/" + field.value;
}
}
</script>
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/array'
require 'active_support/inflector'
require 'active_support/core_ext/class/inheritable_attributes'
require 'active_support/core_ext/duplicable'
class Hash #:nodoc:
def deep_merge(other_hash)
self.merge(other_hash) do |key, oldval, newval|
module ActionMailer
class Base
# call deliver! and then clear the theme out
# need to clear the theme on both success and failure do to errors
def deliver_with_clear_theme_path!(mail = @mail)
begin
deliver_without_clear_theme_path!
ensure
clear_theme_path
# match method names like
# logged_id_super_admin_or_admin?
# or
# logged_in_admin_or_lead?
def method_missing(method_name, *args)
if method_name.to_s.match(/logged_in.*\?/)
roles = method_name.to_s.gsub('logged_in_', '').delete('?').split('_or_')
return false unless logged_in? && current_user.company_id == current_company.id
roles.each do |role|
@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
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
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")
#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"