Skip to content

Instantly share code, notes, and snippets.

View jfriedlaender's full-sized avatar

Joel Friedlaender jfriedlaender

View GitHub Profile
before_save :update_birth_date_fields
private
def update_birth_date_fields
if date_of_birth_changed?
self.birth_month = date_of_birth ? date_of_birth.month : nil
self.birth_day = date_of_birth ? date_of_birth.day : nil
end
end
private
def update_birth_date_fields
if date_of_birth_changed?
self.birth_month = date_of_birth ? date_of_birth.month : nil
self.birth_day = date_of_birth ? date_of_birth.day : nil
end
end
desc "Updating birth dates from date of birth"
task :update_birth_date_fields => :environment do
puts "Updating birth dates from date of birth"
User.where('date_of_birth is not null').each do |u|
u.birth_month = u.date_of_birth.month
u.birth_day = u.date_of_birth.day
u.save
end
@jfriedlaender
jfriedlaender / gist:1120165
Created August 2, 2011 13:22
add birth_day and birth_month fields to person model
rails generate migration add_birth_date_fields_to_users birth_day:integer birth_month:integer
@jfriedlaender
jfriedlaender / gist:1018597
Created June 10, 2011 10:29
Internationalize phone numbers
def self.internationalize_phone_number(number, country)
c = Country[Country.find_by_name(country)[0]]
if c
number = Phony.normalize(number)
number = "#{c.country_code}#{number}" unless number.starts_with?(c.country_code)
end
number = Phony.normalize(number)
number
end
@jfriedlaender
jfriedlaender / hooks_controller.rb
Created April 23, 2011 04:37 — forked from ryansch/hooks_controller.rb
Rails 3 Controller for Chargify Webhooks
require 'digest/md5'
class Chargify::HooksController < ApplicationController
protect_from_forgery :except => :dispatch_handler
before_filter :verify, :only => :dispatch_handler
EVENTS = %w[ test signup_success signup_failure renewal_success renewal_failure payment_success payment_failure billing_date_change subscription_state_change subscription_product_change ].freeze
def dispatch_handler
event = params[:event]