1

I have a locations_controller and inside I have #index and #show action. I have a map on index.html.erb and when user pans/moves on the map #show action should send json data to map to show the listings. I am sending json request to #show action. But it returns an error saying;

ActionView::MissingTemplate (Missing template locations/show, application/show with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
  * "/usr/local/lib/ruby/gems/2.2.0/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates"
  * "/Users/emreozkan/Desktop/yedek/Last.1/app/views"
  * "/usr/local/lib/ruby/gems/2.2.0/gems/web-console-2.0.0.beta3/app/views"
):
  app/controllers/locations_controller.rb:48:in 'show'

here is the request in index.html.erb

<script>

    (function ( $ ) {

      $('#map-canvas').mapSearch({
        request_uri: 'locations/show', 
        initialPosition: [ <%= @initlat %> , <%= @initlng %> ],
        filters_form : '#filters',
        listing_template : function(listing){ 
                    return '<div class="listing">'
                      +     '<h3>'+listing.address + '</h3>'
                      +   '<div class="row">'
                      +        '<div class="col-sm-2">'
                      +         '<img class="thumbnail img-responsive" src="http://dummyimage.com/150x150/000/fff.jpg">'
                      +          '</div>'
                      +        '<div class="col-sm-5">'
                      +           '<p><strong>Address : </strong>' + listing.address+ '</p>'
                      +               '<p>'+'...'+', '+'...'+' '+l'...'+'</p>'
                      +               '<p>Reg Year: ' + '...'+'</p>'
                      +          '</div>'
                      +        '<div class="col-sm-5">'
                      +         '<p><strong>Demo:</strong> '+'...'+'</p>'
                      +         '<p><strong>Demo:</strong> '+'...'+'</p>'
                      +          '</div>'
                      +   '</div>'
                      +  '</div>';
                  },
        marker_clusterer : true
      });
    }( jQuery ));

  </script>

And here is my locations_controller;

class LocationsController < ApplicationController

  def index

    if params[:search].present?   
      location = Geocoder.search(params[:search])
      @locations =location[0]

    else
        @locations = Location.all.first
    end
    @initlat = @locations.latitude
    @initlng = @locations.longitude

  end



  def show

    ne_lat = params[:ne_lat].to_f
    ne_lng = params[:ne_lng].to_f
    sw_lat = params[:sw_lat].to_f
    sw_lng = params[:sw_lng].to_f

    mylatlong2 = Location.all


    locs = {'results' => mylatlong2}
    respond_to do |format|
      format.html
      format.json {render json: locs}
    end
  end
end

I do not know where I am doing wrong with json request. If you can help me I would appreciate. Thank you

1 Answer 1

2

In this line request_uri: 'locations/show' in place of 'locations/show' try using '/locations/show.json' instead.

Hope this one helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.