Skip to content

Instantly share code, notes, and snippets.

View noahhendrix's full-sized avatar

Noah Hendrix noahhendrix

View GitHub Profile
module Filterable
extend ActiveSupport::Concern
module ClassMethods
def filter(filtering_params)
filtering_params.reduce(self) do |relation, (scope_name, value)|
relation.public_send(scope_name, value) if value.present?
end
end
end
<%= content_box "Create a New Product", :size => 75, :alt => true do %>
<%= semantic_form_for (@product ||= Product.new) do |f| %>
<%= f.inputs do %>
<%= f.input :name %>
<%= f.input :accounting_code %>
<%= f.commit_button :button_html => { :class => "button" } %>
<% end %>
<% end %>
<% end %>
<%= semantic_form_for (@activity ||= Activity.new) do |f| %>
<%= f.inputs :name => "Quickly record what you did" do %>
<%= f.input :date, :selected => Date.today, :order => [:month, :day, :year] %>
<%= f.input :category, :collection => [ "Office", "Personal", "Sales" ], :label => "Type", :input_html => { :class => "change-form-options" } %>
<%= f.inputs :rel => "Sales" do %>
<%= f.input :contact_id, :as => :string %>
<% end %>
<%= f.input :notes %>
<%= f.inputs :rel => "Sales Office" do %>
<%= f.input :outcome, :collection => [ "In the bag", "Will get them with some effort", "50-50 chance no matter what we do", "Probably won't get their business", "Waste of time" ] %>
@noahhendrix
noahhendrix / ChangeDateInMetaSearch.rb
Created July 12, 2010 16:47
Sample code to demonstrate ideal behavior in MetaSearch
s = Activity.search
# => #<MetaSearch::Builder:0x000001053b4588 @relation=[#<Activity id: 1...
s.date_gteq = Date.yesterday
# => Sun, 11 Jul 2010
s.to_sql
# => "SELECT \"activities\".* FROM \"activities\" WHERE (\"activities\".\"date\" >= '2010-07-11')"
s.date_gteq = s.date_gteq.beginning_of_week
class Ability
include CanCan::Ability
def initialize(user)
if user.is? :admin
can :read, :all
can :manage, Activity, :user_id => [user.id, *user.asm_ids]
elsif user.is? :supervisor
can :manage, Activity, :user_id => [user.id, *user.asm_ids]
elsif user.is? :ASM
WillPaginate::ViewHelpers.pagination_options[:renderer] = "ProperPagination"
def index
@activities = current_user.activities.search(params[:search]
end
gem 'sqlite3-ruby', :require => 'sqlite3', :group => :development
gem 'mysql', :group => :production
can :read, Contact, :deleted_at => nil
#SELECT * FROM contacts WHERE (deleted_at IS NULL or deleted_at = "")
ActiveRecord::StatementInvalid: PGError: ERROR: column "sales.id" must appear in the GROUP BY clause or be used in an aggregate function
: SELECT "sales".* FROM "sales" WHERE (branch_name = 'St. Joseph') AND ("sales"."invoiced_on" = '2010-08-09') GROUP BY date_part('year', invoiced_on)