Skip to content

Instantly share code, notes, and snippets.

Rails.application.routes.draw do
get 'users/anon', to: 'users#anon'
get 'users/current', to: 'users#current'
post 'users/login', to: 'users#login'
resources :users, only: [:create]
end
class UsersController < ApplicationController
skip_before_action :authenticate_request, only: [:anon]
# create/register a user
def create
# transition anonymous account to full account
updateStatus = @current_user.update(email: params[:email], display_name: params[:display_name], password: params[:password])
if updateStatus
# delete the associated anonymous user
class CreateAnonymousUsers < ActiveRecord::Migration[6.0]
def change
create_table :anonymous_users do |t|
t.string :display_name
t.belongs_to :user, null: false, foreign_key: true
t.timestamps
end
end
end
class CreateUsers < ActiveRecord::Migration[6.0]
def change
create_table :users do |t|
t.string :email
t.string :display_name
t.string :password_digest
t.timestamps
end
end
require 'json'
class MapsAPI
def get_directions(origin, destination, real_request = false)
response = api_endpoint(google_maps_api_key(real_request), origin, destination, real_request)
parsed = JSON.parse(response)
{
'status': parsed['status'],
'distance': parsed['routes'][0]['legs'][0]['distance']['value'].to_i,
{
"geocoded_waypoints": [],
"routes": [
{
"bounds": {}
},
"copyrights": "Map data ©2020",
"legs": [
{
"distance": {