Rails 4 Nivo Slider - Uncaught Exception

时间:2014-08-05 18:22:46

标签: jquery ruby-on-rails ruby-on-rails-4 nivo-slider

我正在尝试为rails 4中的nivo滑块加载所有资源,但我必须遇到问题,因为javascript似乎无法正常工作。

我只使用javascript include标签,这是我的头部。

<head>
<title>FooSite</title>
<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<%= javascript_include_tag 'jquery-1.10.2.min.js' %>
<%= javascript_include_tag 'jquery.nivo.slider.pack' %>
<%= javascript_include_tag 'jquery.nivo.slider' %>
</head>

我在app / assets / js中有所有相关文件,chrome的元素让我知道css也被解释了 - 来自nivo css。

当我将脚本添加到页面时:

<script>
  $(window).load(function() {
    $('#slider').nivoSlider();
  });
</script>

我已经尝试将此脚本放在application.html.erb中,也在视图页面上... 我得到一个未被捕获的异常,说NivoSlider没有定义,所以我猜... JS没有正确链接。

我也尝试将JS文件放在application.js

    //= require jquery
    //= require jquery_ujs
    //= require turbolinks
    //= require skrollr
    //= require jquery.nivo.slider
    //= require jquery.nivo.slider.pack
    //= require main
    //= require plugins
    //= require_tree .

我的滑块HTML看起来像这样:

                <div class="slider-wrapper theme-default">
                <div id="slider" class="nivoSlider">
                    <%= image_tag("toystory.jpg") %> data-thumb="images/toystory.jpg" alt="" />
                    <a href="http://dev7studios.com"><%= image_tag("up.jpg") %> data-thumb="images/up.jpg" alt="" title="This is an example of a caption" /></a>
                    <%= image_tag("walle.jpg")%> data-thumb="images/walle.jpg" alt="" data-transition="slideInLeft" />
                    <%= image_tag("nemo.jpg") %> data-thumb="images/nemo.jpg" alt="" title="#htmlcaption" />
                </div>
                <div id="htmlcaption" class="nivo-html-caption">
                    <strong>This</strong> is an example of a <em>HTML</em> caption with <a href="#">a link</a>. 
                </div>

我很感激帮助。感谢。

**更新**我认为答案在我的日志中,但我不确定如何纠正它。

ActionController::RoutingError (No route matches [GET] "/assets/jquery-1.10.2.min.map"):
  actionpack (4.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.4) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.4) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.4) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.4) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.4) lib/rails/engine.rb:514:in `call'
  railties (4.1.4) lib/rails/application.rb:144:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /Users/ShiftedRec/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
  /Users/ShiftedRec/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
  /Users/ShiftedRec/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

为什么会发生这种情况,我如何将JS链接到这个?不知道为什么.map被附加到文件中。

0 个答案:

没有答案