NoMethodError - undefined method `*' for nil:NilClass - How to store user's HTML5 location to the user's session in Rails?

150 Views Asked by At

My web app is https://proptrics.com

I'm running a Ruby on Rails (v6.0.3.4) application in a Docker container on a network using Docker Compose hosted on a Digital Ocean droplet (Ubuntu 20.04.1 LTS). I'm also using Geokit-rails (2.3.2) for displaying properties close to the user's location.

I'm trying to get the user's HTML5 location on page load and then store this to the user's session so that when the user clicks on the 'Properties Nearby' button, they are shown a search results page. My issue is that it is taking several click attempts of the 'Properties Nearby' button before both the lat and long values are passed into the controller and stored to the user's session.

I'm using an AJAX request to pass the user's HTML5 location (lat and long) into the session via the controller. The javascript in my application.html.erb file that makes the POST requests for lat and long is below:

<script type="text/javascript">
    // Get user's location on page load.
    window.onload = getLocation();

    // Function that gets the location and returns it.
    function getLocation() {
        if(navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
            console.log("Geo Location supported by browser.");
        } else {
            console.log("Geo Location not supported by browser.");
        }
        navigator.permissions.query({name:'geolocation'}).then(function(permissionStatus) {
        console.log('Existing geolocation permission status is ', permissionStatus.state);
            if (permissionStatus.state == 'denied') {
                alert("It looks like you've blocked Proptrics from knowing your location. Please click the blocked location icon on the right side of your address bar and select the 'Always Allow' option.");
            }
        });
    }

    // Function that retrieves the position.
    function showPosition(position) {
        var location = {
            latitude: position.coords.latitude,
            longitude: position.coords.longitude
        }

        $(document).ready(function() {
            var lat = $(this).val();
            $.ajax({
                type: 'post',
                url: '/user_lat',
                data: {lat: position.coords.latitude},
            success: function(data) {
            console.log(data);
            }
            });      
        })

        $(document).ready(function() {
            var long = $(this).val();
            $.ajax({
                    type: 'post',
                    url: '/user_long',
                    data: {long: position.coords.longitude},
                success: function(data) {
                    console.log(data);
                }
            });      
        })
    }

</script>

The lat and long values are passed into the relevant controller methods shown below:

class PropertiesController < ApplicationController

  before_action :set_property, only: [:show, :edit, :update, :destroy, :add_to_portfolio]
  before_action :authenticate_user!, only: [:new, :create, :destroy]
  before_action :set_sidebar

  def show_location
    session[:location_search] = true
    if session[:user_long] && session[:user_lat]
      @properties = Property.by_distance(:origin => [session[:user_lat], session[:user_long]])
    else
      redirect_to root_url
    end
  end

  def user_lat
    session[:user_lat] = params["lat"]
  end

  def user_long
    session[:user_long] = params["long"]
  end

end

Below is the server output when the homepage is visited and the 'get my location' button is pressed:

web_1            | I, [2021-06-27T10:54:44.302215 #1]  INFO -- : Started GET "/" for 37.228.235.151 at 2021-06-27 10:54:44 +0000
web_1            | I, [2021-06-27T10:54:44.306062 #1]  INFO -- : Processing by PublicController#main as HTML
web_1            | I, [2021-06-27T10:54:44.334862 #1]  INFO -- :   Rendering public/main.html.erb within layouts/application
web_1            | I, [2021-06-27T10:54:44.339006 #1]  INFO -- :   Rendered properties/_search.html.erb (Duration: 2.6ms | Allocations: 120)
web_1            | I, [2021-06-27T10:54:44.340445 #1]  INFO -- :   Rendered properties/_location_search.html.erb (Duration: 0.3ms | Allocations: 67)
web_1            | D, [2021-06-27T10:54:44.369036 #1] DEBUG -- :    (27.1ms)  SELECT COUNT(*) FROM "properties"
web_1            | D, [2021-06-27T10:54:44.409488 #1] DEBUG -- :    (35.6ms)  SELECT COUNT(*) FROM "units"
web_1            | D, [2021-06-27T10:54:44.416563 #1] DEBUG -- :    (2.9ms)  SELECT COUNT(*) FROM "leases"
web_1            | D, [2021-06-27T10:54:44.469657 #1] DEBUG -- :    (49.0ms)  SELECT SUM("units"."area") FROM "units"
web_1            | I, [2021-06-27T10:54:44.470982 #1]  INFO -- :   Rendered public/main.html.erb within layouts/application (Duration: 135.0ms | Allocations: 1738)
web_1            | I, [2021-06-27T10:54:44.478015 #1]  INFO -- :   Rendered layouts/nav/_public.html.erb (Duration: 1.9ms | Allocations: 310)
web_1            | I, [2021-06-27T10:54:44.479032 #1]  INFO -- :   Rendered layouts/_footer.html.erb (Duration: 0.0ms | Allocations: 5)
web_1            | I, [2021-06-27T10:54:44.480153 #1]  INFO -- : Completed 200 OK in 173ms (Views: 30.9ms | ActiveRecord: 122.5ms | Allocations: 4898)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:54:44 +0000] "GET / HTTP/1.1" 200 12841 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
web_1            | I, [2021-06-27T10:54:44.579021 #1]  INFO -- : Started GET "/jquery.js" for 37.228.235.151 at 2021-06-27 10:54:44 +0000
web_1            | F, [2021-06-27T10:54:44.581181 #1] FATAL -- :
web_1            | ActionController::RoutingError (No route matches [GET] "/jquery.js"):
web_1            |
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/debug_exceptions.rb:36:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
web_1            | railties (6.0.3.6) lib/rails/rack/logger.rb:37:in `call_app'
web_1            | railties (6.0.3.6) lib/rails/rack/logger.rb:28:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/request_id.rb:27:in `call'
web_1            | rack (2.2.3) lib/rack/method_override.rb:24:in `call'
web_1            | rack (2.2.3) lib/rack/runtime.rb:22:in `call'
web_1            | activesupport (6.0.3.6) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/executor.rb:14:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/static.rb:126:in `call'
web_1            | rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
web_1            | railties (6.0.3.6) lib/rails/engine.rb:527:in `call'
web_1            | puma (4.3.7) lib/puma/configuration.rb:228:in `call'
web_1            | puma (4.3.7) lib/puma/server.rb:713:in `handle_request'
web_1            | puma (4.3.7) lib/puma/server.rb:472:in `process_client'
web_1            | puma (4.3.7) lib/puma/server.rb:328:in `block in run'
web_1            | puma (4.3.7) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
web_1            | I, [2021-06-27T10:54:44.653910 #1]  INFO -- :   Rendering vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout
web_1            | I, [2021-06-27T10:54:44.663195 #1]  INFO -- :   Rendered vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (Duration: 5.0ms | Allocations: 979)
web_1            | I, [2021-06-27T10:54:44.708708 #1]  INFO -- : Started GET "/assets/glassfacade.jpg" for 37.228.235.151 at 2021-06-27 10:54:44 +0000
web_1            | I, [2021-06-27T10:54:44.727250 #1]  INFO -- :   Rendered collection of vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb [82 times] (Duration: 38.6ms | Allocations: 8970)
web_1            | I, [2021-06-27T10:54:44.738286 #1]  INFO -- :   Rendered vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (Duration: 2.7ms | Allocations: 709)
web_1            | I, [2021-06-27T10:54:44.746844 #1]  INFO -- :   Rendering vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:54:44 +0000] "GET /assets/glassfacade.jpg HTTP/1.1" 304 0 "https://proptrics.com/assets/main-0e050075ecef0ff6e955b2e61448a6dec06dc17c1085c2370a3bed40c342d473.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
web_1            | I, [2021-06-27T10:54:44.752541 #1]  INFO -- :   Rendered vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (Duration: 2.1ms | Allocations: 503)
web_1            | I, [2021-06-27T10:54:44.753783 #1]  INFO -- :   Rendered vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (Duration: 98.8ms | Allocations: 20176)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:54:44 +0000] "GET /jquery.js HTTP/1.1" 404 45778 "https://proptrics.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:54:44 +0000] "GET /service-worker.js HTTP/1.1" 304 0 "https://proptrics.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
web_1            | I, [2021-06-27T10:54:54.037179 #1]  INFO -- : Started GET "/" for 128.1.248.42 at 2021-06-27 10:54:54 +0000
web_1            | I, [2021-06-27T10:54:54.038192 #1]  INFO -- : Processing by PublicController#main as */*
web_1            | I, [2021-06-27T10:54:54.042215 #1]  INFO -- :   Rendering public/main.html.erb within layouts/application
web_1            | I, [2021-06-27T10:54:54.044544 #1]  INFO -- :   Rendered properties/_search.html.erb (Duration: 0.4ms | Allocations: 119)
web_1            | I, [2021-06-27T10:54:54.046208 #1]  INFO -- :   Rendered properties/_location_search.html.erb (Duration: 0.2ms | Allocations: 66)
web_1            | D, [2021-06-27T10:54:54.063305 #1] DEBUG -- :    (15.7ms)  SELECT COUNT(*) FROM "properties"
web_1            | D, [2021-06-27T10:54:54.095332 #1] DEBUG -- :    (29.8ms)  SELECT COUNT(*) FROM "units"
web_1            | D, [2021-06-27T10:54:54.100117 #1] DEBUG -- :    (2.6ms)  SELECT COUNT(*) FROM "leases"
web_1            | D, [2021-06-27T10:54:54.165760 #1] DEBUG -- :    (63.5ms)  SELECT SUM("units"."area") FROM "units"
web_1            | I, [2021-06-27T10:54:54.166974 #1]  INFO -- :   Rendered public/main.html.erb within layouts/application (Duration: 123.8ms | Allocations: 1969)
web_1            | I, [2021-06-27T10:54:54.169858 #1]  INFO -- :   Rendered layouts/nav/_public.html.erb (Duration: 0.7ms | Allocations: 310)
web_1            | I, [2021-06-27T10:54:54.171227 #1]  INFO -- :   Rendered layouts/_footer.html.erb (Duration: 0.0ms | Allocations: 5)
web_1            | I, [2021-06-27T10:54:54.172758 #1]  INFO -- : Completed 200 OK in 134ms (Views: 19.3ms | ActiveRecord: 111.6ms | Allocations: 3627)
frontend_1       | 128.1.248.42 - - [27/Jun/2021:10:54:54 +0000] "GET / HTTP/1.1" 200 12841 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36" "-"
web_1            | I, [2021-06-27T10:54:58.886591 #1]  INFO -- : Started POST "/user_lat" for 37.228.235.151 at 2021-06-27 10:54:58 +0000
web_1            | I, [2021-06-27T10:54:58.889960 #1]  INFO -- : Processing by PropertiesController#user_lat as */*
web_1            | I, [2021-06-27T10:54:58.890921 #1]  INFO -- :   Parameters: {"lat"=>"53.3154063"}
web_1            | I, [2021-06-27T10:54:58.887747 #1]  INFO -- : Started POST "/user_long" for 37.228.235.151 at 2021-06-27 10:54:58 +0000
web_1            | I, [2021-06-27T10:54:58.895356 #1]  INFO -- : Processing by PropertiesController#user_long as */*
web_1            | I, [2021-06-27T10:54:58.896158 #1]  INFO -- :   Parameters: {"long"=>"-6.253928999999999"}
web_1            | I, [2021-06-27T10:54:58.907361 #1]  INFO -- : No template found for PropertiesController#user_long, rendering head :no_content
web_1            | I, [2021-06-27T10:54:58.910005 #1]  INFO -- : Completed 204 No Content in 13ms (ActiveRecord: 0.0ms | Allocations: 5309)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:54:58 +0000] "POST /user_long HTTP/1.1" 204 0 "https://proptrics.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
web_1            | I, [2021-06-27T10:54:58.909608 #1]  INFO -- : No template found for PropertiesController#user_lat, rendering head :no_content
web_1            | I, [2021-06-27T10:54:58.914283 #1]  INFO -- : Completed 204 No Content in 22ms (ActiveRecord: 0.0ms | Allocations: 6438)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:54:58 +0000] "POST /user_lat HTTP/1.1" 204 0 "https://proptrics.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
web_1            | I, [2021-06-27T10:54:58.949294 #1]  INFO -- : Started POST "/user_lat" for 37.228.235.151 at 2021-06-27 10:54:58 +0000
web_1            | I, [2021-06-27T10:54:58.952602 #1]  INFO -- : Processing by PropertiesController#user_lat as */*
web_1            | I, [2021-06-27T10:54:58.953683 #1]  INFO -- :   Parameters: {"lat"=>"53.3154063"}
web_1            | I, [2021-06-27T10:54:58.955595 #1]  INFO -- : No template found for PropertiesController#user_lat, rendering head :no_content
web_1            | I, [2021-06-27T10:54:58.956689 #1]  INFO -- : Completed 204 No Content in 2ms (ActiveRecord: 0.0ms | Allocations: 424)
web_1            | I, [2021-06-27T10:54:58.951761 #1]  INFO -- : Started POST "/user_long" for 37.228.235.151 at 2021-06-27 10:54:58 +0000
web_1            | I, [2021-06-27T10:54:58.959555 #1]  INFO -- : Processing by PropertiesController#user_long as */*
web_1            | I, [2021-06-27T10:54:58.960188 #1]  INFO -- :   Parameters: {"long"=>"-6.253928999999999"}
web_1            | I, [2021-06-27T10:54:58.961777 #1]  INFO -- : No template found for PropertiesController#user_long, rendering head :no_content
web_1            | I, [2021-06-27T10:54:58.962621 #1]  INFO -- : Completed 204 No Content in 2ms (ActiveRecord: 0.0ms | Allocations: 424)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:54:58 +0000] "POST /user_long HTTP/1.1" 204 0 "https://proptrics.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:54:58 +0000] "POST /user_lat HTTP/1.1" 204 0 "https://proptrics.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"

The above should pass the lat and long values into the controller so that these values are stored to the session. However, when the 'Properties Nearby' button is pressed, the search results page doesn't show because of an error: NoMethodError in PropertiesController#show_location undefined method `*' for nil:NilClass `This error relates to this line of the properties controller: @properties = Property.by_distance(:origin => [session[:user_lat], session[:user_long]]).

For the production version, I'm redirecting to the previous page when the nil class error occurs but this is only a temporary 'fix' until I resolve the issue. The below is the output:

web_1            | I, [20web_1            | I, [2021-06-27T10:57:56.376970 #1]  INFO -- : Started GET "/show_location" for 37.228.235.151 at 2021-06-27 10:57:56 +0000
web_1            | I, [2021-06-27T10:57:56.377800 #1]  INFO -- : Processing by PropertiesController#show_location as HTML
web_1            | I, [2021-06-27T10:57:56.378814 #1]  INFO -- : Redirected to http://proptrics.com/
web_1            | I, [2021-06-27T10:57:56.378968 #1]  INFO -- : Completed 302 Found in 1ms (ActiveRecord: 0.0ms | Allocations: 370)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:57:56 +0000] "GET /show_location? HTTP/1.1" 302 98 "https://proptrics.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
web_1            | I, [2021-06-27T10:57:56.420445 #1]  INFO -- : Started GET "/" for 37.228.235.151 at 2021-06-27 10:57:56 +0000
web_1            | I, [2021-06-27T10:57:56.422196 #1]  INFO -- : Processing by PublicController#main as HTML
web_1            | I, [2021-06-27T10:57:56.424948 #1]  INFO -- :   Rendering public/main.html.erb within layouts/application
web_1            | I, [2021-06-27T10:57:56.426548 #1]  INFO -- :   Rendered properties/_search.html.erb (Duration: 0.3ms | Allocations: 119)
web_1            | I, [2021-06-27T10:57:56.427552 #1]  INFO -- :   Rendered properties/_location_search.html.erb (Duration: 0.2ms | Allocations: 66)
web_1            | D, [2021-06-27T10:57:56.444109 #1] DEBUG -- :    (15.3ms)  SELECT COUNT(*) FROM "properties"
web_1            | D, [2021-06-27T10:57:56.475457 #1] DEBUG -- :    (29.4ms)  SELECT COUNT(*) FROM "units"
web_1            | D, [2021-06-27T10:57:56.479898 #1] DEBUG -- :    (2.4ms)  SELECT COUNT(*) FROM "leases"
web_1            | D, [2021-06-27T10:57:56.534364 #1] DEBUG -- :    (52.6ms)  SELECT SUM("units"."area") FROM "units"
web_1            | I, [2021-06-27T10:57:56.535459 #1]  INFO -- :   Rendered public/main.html.erb within layouts/application (Duration: 109.6ms | Allocations: 1684)
web_1            | I, [2021-06-27T10:57:56.537673 #1]  INFO -- :   Rendered layouts/nav/_public.html.erb (Duration: 0.7ms | Allocations: 310)
web_1            | I, [2021-06-27T10:57:56.538626 #1]  INFO -- :   Rendered layouts/_footer.html.erb (Duration: 0.0ms | Allocations: 5)
web_1            | I, [2021-06-27T10:57:56.539846 #1]  INFO -- : Completed 200 OK in 117ms (Views: 15.3ms | ActiveRecord: 99.7ms | Allocations: 3031)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:57:56 +0000] "GET / HTTP/1.1" 200 12841 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
web_1            | I, [2021-06-27T10:57:56.638068 #1]  INFO -- : Started GET "/jquery.js" for 37.228.235.151 at 2021-06-27 10:57:56 +0000
web_1            | F, [2021-06-27T10:57:56.639897 #1] FATAL -- :
web_1            | ActionController::RoutingError (No route matches [GET] "/jquery.js"):
web_1            |
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/debug_exceptions.rb:36:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
web_1            | railties (6.0.3.6) lib/rails/rack/logger.rb:37:in `call_app'
web_1            | railties (6.0.3.6) lib/rails/rack/logger.rb:28:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/request_id.rb:27:in `call'
web_1            | rack (2.2.3) lib/rack/method_override.rb:24:in `call'
web_1            | rack (2.2.3) lib/rack/runtime.rb:22:in `call'
web_1            | activesupport (6.0.3.6) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/executor.rb:14:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/static.rb:126:in `call'
web_1            | rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
web_1            | actionpack (6.0.3.6) lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
web_1            | railties (6.0.3.6) lib/rails/engine.rb:527:in `call'
web_1            | puma (4.3.7) lib/puma/configuration.rb:228:in `call'
web_1            | puma (4.3.7) lib/puma/server.rb:713:in `handle_request'
web_1            | puma (4.3.7) lib/puma/server.rb:472:in `process_client'
web_1            | puma (4.3.7) lib/puma/server.rb:328:in `block in run'
web_1            | puma (4.3.7) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
web_1            | I, [2021-06-27T10:57:56.653717 #1]  INFO -- :   Rendering vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout
web_1            | I, [2021-06-27T10:57:56.657619 #1]  INFO -- :   Rendered vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (Duration: 1.3ms | Allocations: 952)
web_1            | I, [2021-06-27T10:57:56.681878 #1]  INFO -- :   Rendered collection of vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb [82 times] (Duration: 18.7ms | Allocations: 8637)
web_1            | I, [2021-06-27T10:57:56.685372 #1]  INFO -- :   Rendered vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (Duration: 1.4ms | Allocations: 681)
web_1            | I, [2021-06-27T10:57:56.686911 #1]  INFO -- :   Rendering vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
web_1            | I, [2021-06-27T10:57:56.688953 #1]  INFO -- :   Rendered vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (Duration: 1.1ms | Allocations: 516)
web_1            | I, [2021-06-27T10:57:56.689839 #1]  INFO -- :   Rendered vendor/cache/ruby/2.7.0/gems/actionpack-6.0.3.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (Duration: 35.2ms | Allocations: 18776)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:57:56 +0000] "GET /jquery.js HTTP/1.1" 404 45833 "https://proptrics.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
web_1            | I, [2021-06-27T10:57:56.893665 #1]  INFO -- : Started GET "/assets/glassfacade.jpg" for 37.228.235.151 at 2021-06-27 10:57:56 +0000
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:57:56 +0000] "GET /assets/glassfacade.jpg HTTP/1.1" 304 0 "https://proptrics.com/assets/main-0e050075ecef0ff6e955b2e61448a6dec06dc17c1085c2370a3bed40c342d473.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
web_1            | I, [2021-06-27T10:57:57.045349 #1]  INFO -- : Started POST "/user_lat" for 37.228.235.151 at 2021-06-27 10:57:57 +0000
web_1            | I, [2021-06-27T10:57:57.047270 #1]  INFO -- : Processing by PropertiesController#user_lat as */*
web_1            | I, [2021-06-27T10:57:57.048021 #1]  INFO -- :   Parameters: {"lat"=>"53.3154147"}
web_1            | I, [2021-06-27T10:57:57.049895 #1]  INFO -- : No template found for PropertiesController#user_lat, rendering head :no_content
web_1            | I, [2021-06-27T10:57:57.050760 #1]  INFO -- : Completed 204 No Content in 2ms (ActiveRecord: 0.0ms | Allocations: 435)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:57:57 +0000] "POST /user_lat HTTP/1.1" 204 0 "https://proptrics.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
web_1            | I, [2021-06-27T10:57:57.079602 #1]  INFO -- : Started POST "/user_long" for 37.228.235.151 at 2021-06-27 10:57:57 +0000
web_1            | I, [2021-06-27T10:57:57.081933 #1]  INFO -- : Processing by PropertiesController#user_long as */*
web_1            | I, [2021-06-27T10:57:57.082741 #1]  INFO -- :   Parameters: {"long"=>"-6.253897599999999"}
web_1            | I, [2021-06-27T10:57:57.084810 #1]  INFO -- : No template found for PropertiesController#user_long, rendering head :no_content
web_1            | I, [2021-06-27T10:57:57.085558 #1]  INFO -- : Completed 204 No Content in 2ms (ActiveRecord: 0.0ms | Allocations: 435)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:57:57 +0000] "POST /user_long HTTP/1.1" 204 0 "https://proptrics.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
frontend_1       | 37.228.235.151 - - [27/Jun/2021:10:57:58 +0000] "GET /service-worker.js HTTP/1.1" 304 0 "https://proptrics.com/service-worker.js" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"

After hitting this error and redirecting 1-4 times (varies in each test), it finally works and shows the search results for nearby properties. So it seems that it is taking several attempts for both the lat and long values to pass into the controller and be stored the user's session.

On this test, it worked the on second time pressing the 'Properties Nearby' button and only performed 1 redirect. The output (non-relevant lines removed to meet SO question character limit) for the successful attempt is below:

web_1            | I, [2021-06-27T11:02:54.606359 #1]  INFO -- : Started GET "/show_location" for 37.228.235.151 at 2021-06-27 11:02:54 +0000
web_1            | I, [2021-06-27T11:03:31.417815 #1]  INFO -- : Started POST "/user_lat" for 37.228.235.151 at 2021-06-27 11:03:31 +0000
web_1            | I, [2021-06-27T11:03:31.420635 #1]  INFO -- : Processing by PropertiesController#user_lat as */*
web_1            | I, [2021-06-27T11:03:31.421987 #1]  INFO -- :   Parameters: {"lat"=>"53.3266432"}
web_1            | I, [2021-06-27T11:03:31.424902 #1]  INFO -- : No template found for PropertiesController#user_lat, rendering head :no_content
web_1            | I, [2021-06-27T11:03:31.426167 #1]  INFO -- : Completed 204 No Content in 3ms (ActiveRecord: 0.0ms | Allocations: 448)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:11:03:31 +0000] "POST /user_lat HTTP/1.1" 204 0 "https://proptrics.com/show_location?" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"
web_1            | I, [2021-06-27T11:03:31.461989 #1]  INFO -- : Started POST "/user_long" for 37.228.235.151 at 2021-06-27 11:03:31 +0000
web_1            | I, [2021-06-27T11:03:31.464224 #1]  INFO -- : Processing by PropertiesController#user_long as */*
web_1            | I, [2021-06-27T11:03:31.465162 #1]  INFO -- :   Parameters: {"long"=>"-6.2455808"}
web_1            | I, [2021-06-27T11:03:31.467126 #1]  INFO -- : No template found for PropertiesController#user_long, rendering head :no_content
web_1            | I, [2021-06-27T11:03:31.467923 #1]  INFO -- : Completed 204 No Content in 2ms (ActiveRecord: 0.0ms | Allocations: 448)
frontend_1       | 37.228.235.151 - - [27/Jun/2021:11:03:31 +0000] "POST /user_long HTTP/1.1" 204 0 "https://proptrics.com/show_location?" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" "-"

How can I make sure that the lat and long location values are passed into the user's session in a single click/process so that the search results are shown the first time that the user clicks on the 'Properties Nearby' button?

I appreciate any help.

0

There are 0 best solutions below