2013-12-16 3 views
0

컨트롤러 누락되었습니다Gmaps4Rails JSON 요청 템플릿

<div style='width: 800px;'> 
    <div id="map" style='width: 800px; height: 400px;'></div> 
</div> 
<script type="text/javascript"> 
    jQuery(document).ready(function() { 
     handler = Gmaps.build('Google'); 
     handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ 
     markers = handler.addMarkers(<%=raw @locations.to_json %>); 
     handler.bounds.extendWith(markers); 
     handler.fitMapToBounds(); 
     }); 
    }); 
</script> 

모든 것이 잘 작동 :

# GET /customers/1 
    # GET /customers/1.json 
    def show 
    @customer = Customer.find(params[:id]) 

    @locations = Gmaps4rails.build_markers(@customer.shipping_addresses) do |location, marker| 
     marker.lat location.latitude 
     marker.lng location.longitude 
     marker.infowindow render_to_string(:partial => "/customers/location", :locals => { :object => location}) 
     marker.title location.name.to_s 
    end 

    # @locations = @customer.shipping_addresses.to_gmaps4rails do |location, marker| 
     # marker.infowindow render_to_string(:partial => "/customers/location", :locals => { :object => location})  
     # marker.title location.name.to_s  
    # end 
    respond_to do |format| 
     format.html # show.html.erb 
     format.json { render json: @customer } 
    end 
    end 

오래된 버전의 보석 (1.5.6) 코드는
보기 댓글을 달았습니다. 하지만 json 페이지에 요청하면. 만약에하면 오류 좌표가 shipping_address됩니다

템플릿 또는 내가 컨트롤러 형식에 대한 배경 조사를 할 수

Missing partial /customers/location with {: locale => [: ru],: formats => [: json],: handlers => [: erb,: builder,: coffee]}. Searched in: * "/ team/mss/app/views" * "/ usr/local/rvm/gems/ruby-1.9.3-p448/gems/twitter-bootstrap-rails-2.2.6/app/views" * "/ usr/local/rvm/gems/ruby-1.9.3-p448/gems/devise-2.2.4/app/views" * "/ usr/local/rvm/gems/ruby-1.9.3-p448/gems/kaminari-0.14.1/app/views " 

이 없습니다.

unless request.format.json? 
     @locations = Gmaps4rails.build_markers(@customer.shipping_addresses) do |location, marker| 
     marker.lat location.latitude 
     marker.lng location.longitude 
     marker.infowindow render_to_string(:partial => "/customers/location", :locals => { :object => location}) 
     marker.title location.name.to_s 
     end 
    end 

만약 그가 json @ locations를하고 있지 않다면. 최신 버전의 heme으로 업그레이드하려고 시도했습니다. 1.5.6, 2.1.1 이전입니다. 행동하는 방법을 생각할 때?

+0

템플릿 나던 존재 하는가? – apneadiving

+0

여보세요, 여기 계신 분? – apneadiving

+0

템플릿이 존재합니다. 요청 유형이 html로 채워지는 경우 유용합니다. 그러나 나는 또한이 컨트롤러 액션에 json 요청을 사용했다. 그리고이 경우 단지 문제가 발생합니다. – galievruslan

답변

0

시도 :

marker.infowindow render_to_string(:partial => "/customers/location", :formats => [:html], :locals => { :object => location}) 
+0

너무 쉬웠습니다. 고맙습니다 – galievruslan