1
我有locations_controller
和裏面我有#index
和#show
操作。我有一個地圖index.html.erb
,當用戶在地圖上移動/移動#show
時,應該發送json數據來映射以顯示列表。我正在發送json請求到#show
操作。但它返回一個錯誤說:缺少模板錯誤爲json返回導軌
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'
這裏是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>
請求,並在這裏是我的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
我不知道我在做什麼錯誤的JSON請求。如果你能幫助我,我將不勝感激。謝謝