This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
class MissingSpecGenerator | |
def spec_file(spec_path, file_name, spec_template, namespace) | |
spec_name = file_name.gsub('.rb', '') + '_spec.rb' | |
if File.exist?("#{spec_path}/#{spec_name}") | |
puts "#{spec_path}/#{spec_name} exists" | |
else | |
puts "#{spec_path}/#{spec_name} missing" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |