Add User and Hydrant classes
This commit is contained in:
parent
9f70bbda4e
commit
1b07d05c8e
|
@ -0,0 +1,7 @@
|
||||||
|
class Hydrant < ActiveRecord::Base
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
def self.find_closest(lat, lng, limit=20)
|
||||||
|
Hydrant.find_by_sql(["SELECT *, (3959 * ACOS(COS(RADIANS(?)) * COS(RADIANS(lat)) * COS(radians(lng) - RADIANS(?)) + SIN(RADIANS(?)) * SIN(RADIANS(lat)))) AS distance FROM hydrants ORDER BY distance LIMIT ?", lat, lng, lat, limit])
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,3 @@
|
||||||
|
class User < ActiveRecord::Base
|
||||||
|
has_many :hydrants
|
||||||
|
end
|
|
@ -0,0 +1,15 @@
|
||||||
|
class CreateUsers < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
create_table :users do |t|
|
||||||
|
t.timestamps
|
||||||
|
t.string :name
|
||||||
|
t.integer :voice_number
|
||||||
|
t.integer :sms_number
|
||||||
|
t.string :email
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
drop_table :users
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,16 @@
|
||||||
|
class CreateHydrants < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
create_table :hydrants do |t|
|
||||||
|
t.timestamps
|
||||||
|
t.decimal :lat
|
||||||
|
t.decimal :lng
|
||||||
|
t.integer :city_id
|
||||||
|
t.integer :user_id
|
||||||
|
end
|
||||||
|
add_index :hydrants, :city_id, :unique => true
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
drop_table :hydrants
|
||||||
|
end
|
||||||
|
end
|
22
db/schema.rb
22
db/schema.rb
|
@ -10,6 +10,26 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 0) do
|
ActiveRecord::Schema.define(:version => 20110223180521) do
|
||||||
|
|
||||||
|
create_table "hydrants", :force => true do |t|
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
t.decimal "lat"
|
||||||
|
t.decimal "lng"
|
||||||
|
t.integer "city_id"
|
||||||
|
t.integer "user_id"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "hydrants", ["city_id"], :name => "index_hydrants_on_city_id", :unique => true
|
||||||
|
|
||||||
|
create_table "users", :force => true do |t|
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
t.string "name"
|
||||||
|
t.integer "voice_number"
|
||||||
|
t.integer "sms_number"
|
||||||
|
t.string "email"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
13262
db/seeds.rb
13262
db/seeds.rb
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,11 @@
|
||||||
|
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||||
|
|
||||||
|
# This model initially had no columns defined. If you add columns to the
|
||||||
|
# model remove the '{}' from the fixture names and add the columns immediately
|
||||||
|
# below each fixture, per the syntax in the comments below
|
||||||
|
#
|
||||||
|
one: {}
|
||||||
|
# column: value
|
||||||
|
#
|
||||||
|
two: {}
|
||||||
|
# column: value
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||||
|
|
||||||
|
# This model initially had no columns defined. If you add columns to the
|
||||||
|
# model remove the '{}' from the fixture names and add the columns immediately
|
||||||
|
# below each fixture, per the syntax in the comments below
|
||||||
|
#
|
||||||
|
one: {}
|
||||||
|
# column: value
|
||||||
|
#
|
||||||
|
two: {}
|
||||||
|
# column: value
|
|
@ -0,0 +1,8 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class HydrantTest < ActiveSupport::TestCase
|
||||||
|
# Replace this with your real tests.
|
||||||
|
test "the truth" do
|
||||||
|
assert true
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class UserTest < ActiveSupport::TestCase
|
||||||
|
# Replace this with your real tests.
|
||||||
|
test "the truth" do
|
||||||
|
assert true
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue