我有一个locations_controller
,内部有#index
和#show
动作。我在index.html.erb
上有一张地图,当用户在地图上移动/移动#show
时,操作应将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请求在哪里做错了。如果你能帮助我,我将不胜感激。谢谢
答案 0 :(得分:2)
在此行request_uri: 'locations/show'
代替'locations/show'
尝试使用'/locations/show.json'
代替。
希望这个有帮助!