2016-08-04 80 views
-1

它首次添加到項目中的輪播中。她正確顯示。在將卡片添加到另一個頁面輪播中斷後。如何使一個腳本代表一個頁面,併爲對方?Rails。針對不同腳本的不同頁面

的application.js:

//= require jquery 
//= require bootstrap-sprockets 
//= require bootstrap 
//= require jquery_ujs 
//= require jquery.turbolinks 
//= require jquery.validate 
//= require validation 
//= require jquery-1.5.min 
//= require underscore 
//= require gmaps/google 
//= require markerclusterer 
//= require google_maps 
//= require jcarousel 
//= require turbolinks 
//= require_tree . 

$(document).ready(function() { 
    // Initialise the first and second carousel by class selector. 
    // Note that they use both the same configuration options (none in this case). 
    $('.d-carousel .carousel').jcarousel({ 
     scroll: 1 
    }); 

}); 

google_maps.js:

$(function() { 
    handler = Gmaps.build('Google'); 
    handler.buildMap({provider: {scrollwheel: false}, internal: {id: 'map'}}, function() { 
     var ht = 80; 
     var wt = 80; 
     markers = handler.addMarkers([ 
      { 
       "lat": 23.953052, 
       "lng": 56.677616, 
       "picture": { 
        "url": src="../../assets/kafe.png", 
        "width": wt, 
        "height": ht 
       }, 
       "infowindow": "kafe" 
      } 
     ]); 
     handler.bounds.extendWith(markers); 
     handler.fitMapToBounds(); 
    }); 
    google.maps.event.addDomListener(window, "load", initialize); 
}); 

jcarousel.js:

(function ($) { 
     $.jcarousel = function (e, o) { ... })(jQuery); 

回答

0

嘗試祛瘀e

//= require underscore 
//= require gmaps/google 
//= require markerclusterer 

從application.js行並添加到google_maps.js。 在視圖中添加行<%= javascript_include_tag "google_maps.js", params[:you_controller] %>。 在配置/初始化/ assets.rb添加

%w(controller_one controller_two controller_three).each do |controller| 
     Rails.application.config.assets.precompile += ["#{controller}.js.coffee", "#{controller}.css"] 
    end 
    Rails.application.config.assets.precompile += %w(google_maps.js) 

,並重新啓動服務器 和檢查工作jquery.turbolinks

相關問題