apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.26k stars 382 forks source link

JSON request Template is missing #411

Closed galievruslan closed 10 years ago

galievruslan commented 10 years ago

Controller:

  # 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

Old version gem code commented
View:

<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>

Everything works fine. But if you make a request to the json page. What if there will shipping_address coordinates in error:

Template is missing

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 "

Alternatively I can do a background check on the controller format. And if he is not doing json @ locations. Tried to upgrade to the latest version heme stood before 1.5.6, 2.1.1 now. As you consider how to act?

apneadiving commented 10 years ago

Please ask questions on stackoverflow.

Particularly when they are not related to the gem itself

galievruslan commented 10 years ago

http://stackoverflow.com/questions/20605133/gmaps4rails-json-request-template-is-missing

Plaese help :)