Skip to content

Instantly share code, notes, and snippets.

@seanpdoyle
Last active January 2, 2016 11:09
Show Gist options
  • Save seanpdoyle/8294526 to your computer and use it in GitHub Desktop.
Save seanpdoyle/8294526 to your computer and use it in GitHub Desktop.
Code example for `paperclip-location`
require 'paperclip'
class CreatePlaces < ActiveRecord::Migration
include Paperclip::Schema
def self.up
create_table :places do |t|
t.boolean :location_locked, default: false, null: false
t.decimal :lat, precision: 10, scale: 15
t.decimal :lng, precision: 10, scale: 15
end
add_attachment :places, :photo
end
end
development:
adapter: sqlite3
database: development.sqlite3
pool: 5
timeout: 5000
source 'https://rubygems.org'
ruby '2.0.0'
gem 'activerecord'
gem 'paperclip-location'
gem 'sqlite3'
GEM
remote: https://rubygems.org/
specs:
activemodel (4.0.2)
activesupport (= 4.0.2)
builder (~> 3.1.0)
activerecord (4.0.2)
activemodel (= 4.0.2)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.2)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.2)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.1)
atomic (1.1.14)
builder (3.1.4)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.3)
climate_control (>= 0.0.3, < 1.0)
exifr (1.1.3)
i18n (0.6.9)
mime-types (2.0)
minitest (4.7.5)
multi_json (1.8.2)
paperclip (3.5.2)
activemodel (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (~> 0.5.3)
mime-types
paperclip-location (0.0.5)
exifr (~> 1.1)
paperclip (~> 3.5)
sqlite3 (1.3.8)
thread_safe (0.1.3)
atomic
tzinfo (0.3.38)
PLATFORMS
ruby
DEPENDENCIES
activerecord
paperclip-location
sqlite3
#!/usr/bin/env ruby
#
# Scrape the location from a JPG file
require "active_record"
require "paperclip/location"
require "./place"
Paperclip::Location::Processor.register! :location
unless image_file = ARGV.pop
raise ArgumentError, "Don't forget to pass in the path to the image"
end
ActiveRecord::Base.establish_connection YAML.load_file("database.yml")["development"]
puts "Processing #{image_file}....."
puts
puts "-------"
puts
place = Place.new photo: File.open(image_file)
puts
puts "-------"
puts
puts "Processed file."
puts "------- latitude: #{place.lat}"
puts "------- longitude: #{place.lng}"
class Place < ActiveRecord::Base
include Paperclip::Glue
has_attached_file :photo, styles: { large: '600x600#' },
processors: [:thumbnail, :location]
end
require 'bundler/setup'
require 'active_record'
include ActiveRecord::Tasks
DatabaseTasks.env = 'development'
DatabaseTasks.db_dir = '.'
DatabaseTasks.database_configuration = YAML.load(File.read('database.yml'))
DatabaseTasks.migrations_paths = 'migrate'
task :environment do
ActiveRecord::Base.configurations = DatabaseTasks.database_configuration
ActiveRecord::Base.establish_connection DatabaseTasks.env
end
load 'active_record/railties/databases.rake'
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140110012324) do
create_table "places", force: true do |t|
t.boolean "location_locked", default: false, null: false
t.decimal "lat", precision: 10, scale: 15
t.decimal "lng", precision: 10, scale: 15
t.string "photo_file_name"
t.string "photo_content_type"
t.integer "photo_file_size"
t.datetime "photo_updated_at"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment