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
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
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 '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
<%= 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
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
class Recipe < ActiveRecord::Base | |
belongs_to :style, :counter_cache => true | |
attribute_method_suffix '_previous_change' | |
private | |
def attribute_previous_change(attr) | |
self.changes[attr] |
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
class Post < ActiveRecord::Base | |
has_many :authors | |
has_many :post_comments | |
attr_accessor :post_authors_cache, :post_comments_cache | |
def post_authors | |
@post_authors_cache ||= begin | |
process_post |
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
class Post < ActiveRecord::Base | |
has_many :authors | |
attr_accessor :post_authors_cache | |
def post_authors | |
process_post_authors if post_authors_cache.nil? | |
post_authors_cache | |
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
page << <<-JS | |
var manager = $('office_manager_attr').value; | |
var office_admin = $('office_office_admin_attr').value; | |
var managers_arr = Array(); | |
var office_admins_arr = Array(); | |
managers_arr.push(new Option('', '')); | |
office_admins_arr.push(new Option('', '')); | |
JS | |
@agents.each do |agent| | |
page << <<-JS |