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 Location < ActiveRecord::Base | |
belongs_to :located, :polymorphic => true | |
geocoded_by :address | |
before_validation :geocode, :if => :changed? | |
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
Event.create(name: 'Coffee Party', location_attributes: {address: '3126 16th St. San Francisco, CA 94103'}) | |
# (0.2ms) begin transaction | |
# SQL (2.8ms) INSERT INTO "events" ("created_at", "name", "updated_at") VALUES (?, ?, ?) [["created_at", Fri, 22 Nov 2013 19:09:51 UTC +00:00], ["name", "Coffee Party"], ["updated_at", Fri, 22 Nov 2013 19:09:51 UTC +00:00]] | |
# SQL (0.3ms) INSERT INTO "locations" ("address", "created_at", "latitude", "located_id", "located_type", "longitude", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?) [["address", "3126 16th St. San Francisco, CA 94103"], ["created_at", Fri, 22 Nov 2013 19:09:51 UTC +00:00], ["latitude", 37.7648968], ["located_id", 2], ["located_type", "Event"], ["longitude", -122.4225344], ["updated_at", Fri, 22 Nov 2013 19:09:51 UTC +00:00]] | |
# (2.2ms) commit transaction | |
# <Event id: 2, name: "Coffee Party", created_at: "2013-11-22 19:09:51", updated_at: "2013-11-22 19:09:51"> |
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 Event < ActiveRecord::Base | |
has_one :location, as: :located, dependent: :destroy | |
accepts_nested_attributes_for :location | |
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
class CreateLocations < ActiveRecord::Migration | |
def change | |
create_table :locations do |t| | |
t.string :address | |
t.float :latitude | |
t.float :longitude | |
t.integer :located_id | |
t.string :located_type | |
t.timestamps |
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
Gem::Specification.new do |s| | |
s.files = `git ls-files`.split("\n") | |
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
twitter_regex = /(@[A-Za-z0-9_]{1,15})/i | |
formatted_phone_regex = /((?:\+?(\d{1,3}))?[- (]*(\d{3})[- )]*(\d{3})[- ]*(\d{4})(?: *x(\d+))?\b)/i | |
email_regex = /(\b[^\s]+?\s*(@|at)\s*[^\s]+?\.[^\s]+?\b)/i # Very general so as to catch BS |
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 Message < ActiveRecord::Base | |
validates :body, cold_shoulder: true | |
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
Gem::Specification.new do |s| | |
s.files = 'lib/cold_shoulder.rb' | |
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
class UserSession < Authlogic::Session::Base | |
validate :check_presence | |
# Without the following method, calling persisted? on UserSession fails, | |
# which is needed for polymorphic_url when called with a UserSession. | |
def destroyed? | |
false | |
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
# Logs are saying: | |
# | |
# Cache read: geocoded/New York, NY | |
# Cache fetch_hit: geocoded/New York, NY | |
# Google Geocoding API error: over query limit. | |
# | |
# Seems to hit a match, then query google anway | |
def self.geocode(address) | |
location = Rails.cache.fetch("geocoded/#{address}") do |