From 0a2beaa5702baf228d84703d7269f0707caff84e Mon Sep 17 00:00:00 2001 From: gauravano Date: Wed, 11 Oct 2017 00:19:21 +0530 Subject: [PATCH] google map partial --- .byebug_history | 25 +++++++++++++++++-- Gemfile | 1 + Gemfile.lock | 2 ++ app/controllers/home_controller.rb | 5 ++++ app/models/userdetail.rb | 18 +++++++++++++ app/views/home/profile.html.erb | 6 +++++ config/routes.rb | 3 ++- ...dd_latitude_and_longitude_to_userdetail.rb | 6 +++++ db/schema.rb | 4 ++- 9 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20171010165657_add_latitude_and_longitude_to_userdetail.rb diff --git a/.byebug_history b/.byebug_history index ac8435b..1d91b38 100644 --- a/.byebug_history +++ b/.byebug_history @@ -1,4 +1,27 @@ c +@longitude +@latitude +c +@latitude +c +@latitude +c +@latitude +c +Userdetail.where(user_id: current_user.id)[0].save +Userdetail.where(user_id: current_user.id)[0].address = "adarsh nagar" +Userdetail.where(user_id: current_user.id)[0] +Userdetail.where(user_id: current_user.id)[0].address = "adarsh nagar" +Userdetail.where(user_id: current_user.id)[0].address = adarsh nagar +Userdetail.where(user_id: current_user.id)[0] +current_user +@latitude +latitude +@user.latitude +c +@user.latitude +@user +c @user[0].name @user[0] user[1] @@ -15,8 +38,6 @@ Userdetail.all @user.name @user.profile_picture @user.coverpic -@user - @user @user.coverpic @user diff --git a/Gemfile b/Gemfile index 79f0f8b..8e068be 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ gem 'rails', '4.2.8' gem 'devise' # Use sqlite3 as the database for Active Record gem 'sqlite3' +gem 'geocoder' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets diff --git a/Gemfile.lock b/Gemfile.lock index cc4f647..efc0fe7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -60,6 +60,7 @@ GEM erubis (2.7.0) execjs (2.7.0) ffi (1.9.18) + geocoder (1.4.4) globalid (0.4.0) activesupport (>= 4.2.0) i18n (0.8.6) @@ -172,6 +173,7 @@ DEPENDENCIES byebug coffee-rails (~> 4.1.0) devise + geocoder jbuilder (~> 2.0) jquery-rails rails (= 4.2.8) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 72f760e..b11bc3d 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -11,6 +11,11 @@ def homepage def profile @user = Userdetail.where(user_id: current_user.id)[0] + + # @latitude = Geocoder.coordinates(Userdetail.where(user_id: current_user.id)[0].address) + @latitude = Geocoder.coordinates( :"bvp,paschim vihar,delhi")[0] + @longitude = Geocoder.coordinates(:"bvp,paschim vihar,delhi")[1] + byebug end def upload_image diff --git a/app/models/userdetail.rb b/app/models/userdetail.rb index 5942670..b39f2b7 100644 --- a/app/models/userdetail.rb +++ b/app/models/userdetail.rb @@ -6,4 +6,22 @@ class Userdetail < ActiveRecord::Base validates :numslots, presence: true validates :numvacant, presence: true validates :mobilenum, presence: true + + # geocoded_by :address, :latitude => :lat, :longitude => :lon + # geocoded_by :address + # after_validation :geocode + # + # # def address userid + # # Userdetail.where(user_id: userid)[0].address + # # end + # + # def getlatitude userid + # Userdetail.where(user_id: userid)[0].latitude + # end + # + # def getlongitude userid + # Userdetail.where(user_id: userid)[0].longitude + # end + + end diff --git a/app/views/home/profile.html.erb b/app/views/home/profile.html.erb index 46d60ab..53a03ff 100644 --- a/app/views/home/profile.html.erb +++ b/app/views/home/profile.html.erb @@ -115,6 +115,12 @@
User Name: <%= @user.name %>

Email: <%= current_user.email %>

+ + + +
+

<%= %>

+ diff --git a/config/routes.rb b/config/routes.rb index fa9e1bf..35f900d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,9 @@ Rails.application.routes.draw do + resources :prices resources :userdetails devise_for :users - root 'home#index' + get 'home/profile' => 'home#profile' ,as:'user_profile' post 'home/upload_image' post 'home/upload_coverpic' diff --git a/db/migrate/20171010165657_add_latitude_and_longitude_to_userdetail.rb b/db/migrate/20171010165657_add_latitude_and_longitude_to_userdetail.rb new file mode 100644 index 0000000..8b16381 --- /dev/null +++ b/db/migrate/20171010165657_add_latitude_and_longitude_to_userdetail.rb @@ -0,0 +1,6 @@ +class AddLatitudeAndLongitudeToUserdetail < ActiveRecord::Migration + def change + add_column :userdetails, :latitude, :float + add_column :userdetails, :longitude, :float + end +end diff --git a/db/schema.rb b/db/schema.rb index 9879fcd..53be149 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171010122825) do +ActiveRecord::Schema.define(version: 20171010165657) do create_table "orgcategories", force: :cascade do |t| t.string "name" @@ -43,6 +43,8 @@ t.string "mobilenum" t.string "profile_picture" t.string "coverpic" + t.float "latitude" + t.float "longitude" end add_index "userdetails", ["user_id"], name: "index_userdetails_on_user_id"