JavaScript 无法通过 Rails 中的引导模板运行

2023-12-02

我创建了一个新的 Rails 应用程序并安装了所有必要的 gem。添加了所有文件。更新了 application.js 文件。一切正常,但由于某种原因,所有与 javascript 相关的东西都不起作用。我使用这个模板:

https://startbootstrap.com/template-overviews/creative/

我还使用了导航栏的一部分。 我缺少什么?如果您需要更多信息,请告诉我!

应用程序/资产/javascripts/应用程序.js

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery-ui
//= require magnific-popup
//= require welcomes
//= require jquery.easing
//= require scrollReveal
//= require jquery_ujs
//= require turbolinks
//= require_tree .

Gemfile

source 'https://rubygems.org'

gem 'jquery-ui-rails'
gem 'scrollreveal-rails'
gem 'magnific-popup-rails', '~> 1.1.0'
gem 'jquery-easing-rails'

gem "font-awesome-rails"
gem 'bootstrap-sass'

gem 'rails', '4.2.0'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

应用程序/资产/javascripts/欢迎.js

(function($) {
    "use strict"; // Start of use strict

    // jQuery for page scrolling feature - requires jQuery Easing plugin
    $('a.page-scroll').bind('click', function(event) {
        var $anchor = $(this);
        $('html, body').stop().animate({
            scrollTop: ($($anchor.attr('href')).offset().top - 50)
        }, 1250, 'easeInOutExpo');
        event.preventDefault();
    });

    // Highlight the top nav as scrolling occurs
    $('body').scrollspy({
        target: '.navbar-fixed-top',
        offset: 51
    });

    // Closes the Responsive Menu on Menu Item Click
    $('.navbar-collapse ul li a').click(function() {
        $('.navbar-toggle:visible').click();
    });

    // Offset for Main Navigation
    $('#mainNav').affix({
        offset: {
            top: 100
        }
    })

    // Initialize and Configure Scroll Reveal Animation
    window.sr = ScrollReveal();
    sr.reveal('.sr-icons', {
        duration: 600,
        scale: 0.3,
        distance: '0px'
    }, 200);
    sr.reveal('.sr-button', {
        duration: 1000,
        delay: 200
    });
    sr.reveal('.sr-contact', {
        duration: 600,
        scale: 0.3,
        distance: '0px'
    }, 300);

    // Initialize and Configure Magnific Popup Lightbox Plugin
    $('.popup-gallery').magnificPopup({
        delegate: 'a',
        type: 'image',
        tLoading: 'Loading image #%curr%...',
        mainClass: 'mfp-img-mobile',
        gallery: {
            enabled: true,
            navigateByImgClick: true,
            preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
        },
        image: {
            tError: '<a href="%url%">The image #%curr%</a> could not be loaded.'
        }
    });

})(jQuery); // End of use strict

_header.html.erb

<nav id="mainNav" class="navbar navbar-default navbar-fixed-top">
  <div class="container-fluid">

    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span> Menu <i class="fa fa-bars"></i>
      </button>
      <a class="navbar-brand page-scroll" href="#page-top">Start Bootstrap</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav navbar-right">
        <li>
            <a class="page-scroll" href="#about">About</a>
        </li>
        <li>
            <a class="page-scroll" href="#services">Services</a>
        </li>
        <li>
            <a class="page-scroll" href="#portfolio">Portfolio</a>
        </li>
        <li>
            <a class="page-scroll" href="#contact">Contact</a>
        </li>
      </ul>
    </div>
    <!-- /.navbar-collapse -->

  </div>
  <!-- /.container-fluid -->
</nav>

<header>
  <div class="header-content">

    <div class="header-content-inner">
      <h1 id="homeHeading">Your Favorite Source of Free Bootstrap Themes</h1>
      <hr>
      <p>Start Bootstrap can help you build better websites using the Bootstrap CSS framework! Just download your template and start going, no strings attached!</p>
      <a href="#about" class="btn btn-primary btn-xl page-scroll">Find Out More</a>
    </div>

  </div>
</header>

索引.html.erb

<section class="bg-primary" id="about">
  <div class="container">
    <div class="row">
        <div class="col-lg-8 col-lg-offset-2 text-center">
          <h2 class="section-heading">We've got what you need!</h2>
          <hr class="light">
          <p class="text-faded">Start Bootstrap has everything you need to get your new website up and running in no time! All of the templates and themes on Start Bootstrap are open source, free to download, and easy to use. No strings attached!</p>
          <a href="#services" class="page-scroll btn btn-default btn-xl sr-button">Get Started!</a>
        </div>
    </div>
  </div>
</section>

<section id="services">

  <div class="container">
    <div class="row">
      <div class="col-lg-12 text-center">
        <h2 class="section-heading">At Your Service</h2>
        <hr class="primary">
      </div>
    </div>
  </div>

  <div class="container">
    <div class="row">

      <div class="col-lg-3 col-md-6 text-center">
        <div class="service-box">
          <i class="fa fa-4x fa-diamond text-primary sr-icons"></i>
          <h3>Sturdy Templates</h3>
          <p class="text-muted">Our templates are updated regularly so they don't break.</p>
        </div>
      </div>
      <div class="col-lg-3 col-md-6 text-center">
        <div class="service-box">
          <i class="fa fa-4x fa-paper-plane text-primary sr-icons"></i>
          <h3>Ready to Ship</h3>
          <p class="text-muted">You can use this theme as is, or you can make changes!</p>
        </div>
      </div>
      <div class="col-lg-3 col-md-6 text-center">
        <div class="service-box">
          <i class="fa fa-4x fa-newspaper-o text-primary sr-icons"></i>
          <h3>Up to Date</h3>
          <p class="text-muted">We update dependencies to keep things fresh.</p>
        </div>
      </div>
      <div class="col-lg-3 col-md-6 text-center">
        <div class="service-box">
          <i class="fa fa-4x fa-heart text-primary sr-icons"></i>
          <h3>Made with Love</h3>
          <p class="text-muted">You have to make your websites with love these days!</p>
        </div>
      </div>

    </div>
  </div>

</section>

<section class="no-padding" id="portfolio">
  <div class="container-fluid">
    <div class="row no-gutter popup-gallery">

      <div class="col-lg-4 col-sm-6">
        <a href="img/portfolio/fullsize/1.jpg" class="portfolio-box">
          <%= image_tag("1.jpg", alt: "#", :class => "img-responsive") %>
          <div class="portfolio-box-caption">
            <div class="portfolio-box-caption-content">
              <div class="project-category text-faded">
                Category
              </div>
              <div class="project-name">
                Project Name
              </div>
            </div>
          </div>
        </a>
      </div>

      <div class="col-lg-4 col-sm-6">
        <a href="img/portfolio/fullsize/2.jpg" class="portfolio-box">
          <%= image_tag("2.jpg", alt: "#", :class => "img-responsive") %>
          <div class="portfolio-box-caption">
            <div class="portfolio-box-caption-content">
              <div class="project-category text-faded">
                Category
              </div>
              <div class="project-name">
                Project Name
              </div>
            </div>
          </div>
        </a>
      </div>

      <div class="col-lg-4 col-sm-6">
        <a href="img/portfolio/fullsize/3.jpg" class="portfolio-box">
          <%= image_tag("3.jpg", alt: "#", :class => "img-responsive") %>
          <div class="portfolio-box-caption">
            <div class="portfolio-box-caption-content">
              <div class="project-category text-faded">
                Category
              </div>
              <div class="project-name">
                Project Name
              </div>
            </div>
          </div>
        </a>
      </div>

      <div class="col-lg-4 col-sm-6">
        <a href="img/portfolio/fullsize/4.jpg" class="portfolio-box">
          <%= image_tag("4.jpg", alt: "#", :class => "img-responsive") %>
          <div class="portfolio-box-caption">
            <div class="portfolio-box-caption-content">
              <div class="project-category text-faded">
                Category
              </div>
              <div class="project-name">
                Project Name
              </div>
            </div>
          </div>
        </a>
      </div>

      <div class="col-lg-4 col-sm-6">
        <a href="img/portfolio/fullsize/5.jpg" class="portfolio-box">
          <%= image_tag("5.jpg", alt: "#", :class => "img-responsive") %>
          <div class="portfolio-box-caption">
            <div class="portfolio-box-caption-content">
              <div class="project-category text-faded">
                Category
              </div>
              <div class="project-name">
                Project Name
              </div>
            </div>
          </div>
        </a>
      </div>

      <div class="col-lg-4 col-sm-6">
        <a href="img/portfolio/fullsize/6.jpg" class="portfolio-box">
          <%= image_tag("6.jpg", alt: "#", :class => "img-responsive") %>
          <div class="portfolio-box-caption">
            <div class="portfolio-box-caption-content">
              <div class="project-category text-faded">
                Category
              </div>
              <div class="project-name">
                Project Name
              </div>
            </div>
          </div>
        </a>
      </div>

    </div>
  </div>
</section>

<aside class="bg-dark">
  <div class="container text-center">
    <div class="call-to-action">
      <h2>Free Download at Start Bootstrap!</h2>
      <a href="http://startbootstrap.com/template-overviews/creative/" class="btn btn-default btn-xl sr-button">Download Now!</a>
    </div>
  </div>
</aside>

<section id="contact">
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 text-center">
        <h2 class="section-heading">Let's Get In Touch!</h2>
        <hr class="primary">
        <p>Ready to start your next project with us? That's great! Give us a call or send us an email and we will get back to you as soon as possible!</p>
      </div>
      <div class="col-lg-4 col-lg-offset-2 text-center">
        <i class="fa fa-phone fa-3x sr-contact"></i>
        <p>123-456-6789</p>
      </div>
      <div class="col-lg-4 text-center">
        <i class="fa fa-envelope-o fa-3x sr-contact"></i>
        <p><a href="mailto:[email protected]">[email protected]</a></p>
      </div>
    </div>
  </div>
</section>

application.html.erb

<!DOCTYPE html>
<html>
<head>
  <title>Template</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>

  <%= render 'layouts/shim' %>
</head>
<body>

<%= render 'layouts/header' %>
<%= yield %>
<%= render 'layouts/footer' %>

</body>
</html>

应用程序.css.scss

@import "bootstrap-sprockets";
@import "bootstrap";
@import "jquery-ui/all";
@import "font-awesome";
@import "magnific-popup";

html,
body {
  height: 100%;
  width: 100%;
}

body {
  font-family: 'Merriweather', 'Helvetica Neue', Arial, sans-serif;
}

hr {
  border-color: #F05F40;
  border-width: 3px;
  max-width: 50px;
}

hr.light {
  border-color: white;
}

a {
  -webkit-transition: all 0.35s;
  -moz-transition: all 0.35s;
  transition: all 0.35s;
  color: #F05F40;
}

a:hover,
a:focus {
  color: #eb3812;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
}

p {
  font-size: 16px;
  line-height: 1.5;
  margin-bottom: 20px;
}

.bg-primary {
  background-color: #F05F40;
}

.bg-dark {
  background-color: #222222;
  color: white;
}

.text-faded {
  color: rgba(255, 255, 255, 0.7);
}

section {
  padding: 100px 0;
}

aside {
  padding: 50px 0;
}

.no-padding {
  padding: 0;
}

.navbar-default {
  background-color: white;
  border-color: rgba(34, 34, 34, 0.05);
  font-family: 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
  -webkit-transition: all 0.35s;
  -moz-transition: all 0.35s;
  transition: all 0.35s;
}

.navbar-default .navbar-header .navbar-brand {
  color: #F05F40;
  font-family: 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
  font-weight: 700;
  text-transform: uppercase;
}

.navbar-default .navbar-header .navbar-brand:hover,
.navbar-default .navbar-header .navbar-brand:focus {
  color: #eb3812;
}

.navbar-default .navbar-header .navbar-toggle {
  font-weight: 700;
  font-size: 12px;
  color: #222222;
  text-transform: uppercase;
}

.navbar-default .nav > li > a,
.navbar-default .nav > li > a:focus {
  text-transform: uppercase;
  font-weight: 700;
  font-size: 13px;
  color: #222222;
}

.navbar-default .nav > li > a:hover,
.navbar-default .nav > li > a:focus:hover {
  color: #F05F40;
}

.navbar-default .nav > li.active > a,
.navbar-default .nav > li.active > a:focus {
  color: #F05F40 !important;
  background-color: transparent;
}

.navbar-default .nav > li.active > a:hover,
.navbar-default .nav > li.active > a:focus:hover {
  background-color: transparent;
}

@media (min-width: 768px) {

  .navbar-default {
    background-color: transparent;
    border-color: rgba(255, 255, 255, 0.3);
  }

  .navbar-default .navbar-header .navbar-brand {
    color: rgba(255, 255, 255, 0.7);
  }

  .navbar-default .navbar-header .navbar-brand:hover,
  .navbar-default .navbar-header .navbar-brand:focus {
    color: white;
  }

  .navbar-default .nav > li > a,
  .navbar-default .nav > li > a:focus {
    color: rgba(255, 255, 255, 0.7);
  }

  .navbar-default .nav > li > a:hover,
  .navbar-default .nav > li > a:focus:hover {
    color: white;
  }

  .navbar-default.affix {
    background-color: white;
    border-color: rgba(34, 34, 34, 0.05);
  }

  .navbar-default.affix .navbar-header .navbar-brand {
    color: #F05F40;
    font-size: 14px;
  }

  .navbar-default.affix .navbar-header .navbar-brand:hover,
  .navbar-default.affix .navbar-header .navbar-brand:focus {
    color: #eb3812;
  }

  .navbar-default.affix .nav > li > a,
  .navbar-default.affix .nav > li > a:focus {
    color: #222222;
  }

  .navbar-default.affix .nav > li > a:hover,
  .navbar-default.affix .nav > li > a:focus:hover {
    color: #F05F40;
  }

}

header {
  position: relative;
  width: 100%;
  min-height: auto;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  background-size: cover;
  -o-background-size: cover;
  background-position: center;
  background-image: asset-data-url("header.jpg");
  text-align: center;
  color: white;
}

header .header-content {
  position: relative;
  text-align: center;
  padding: 100px 15px 100px;
  width: 100%;
}

header .header-content .header-content-inner h1 {
  font-weight: 700;
  text-transform: uppercase;
  margin-top: 0;
  margin-bottom: 0;
  font-size: 30px;
}

header .header-content .header-content-inner hr {
  margin: 30px auto;
}

header .header-content .header-content-inner p {
  font-weight: 300;
  color: rgba(255, 255, 255, 0.7);
  font-size: 16px;
  margin-bottom: 50px;
}

@media (min-width: 768px) {

  header {
    min-height: 100%;
  }

  header .header-content {
    position: absolute;
    top: 50%;
    -webkit-transform: translateY(-50%);
    -ms-transform: translateY(-50%);
    transform: translateY(-50%);
    padding: 0 50px;
  }

  header .header-content .header-content-inner {
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
  }

  header .header-content .header-content-inner h1 {
    font-size: 50px;
  }

  header .header-content .header-content-inner p {
    font-size: 18px;
    max-width: 80%;
    margin-left: auto;
    margin-right: auto;
  }

}

.section-heading {
  margin-top: 0;
}

.service-box {
  max-width: 400px;
  margin: 50px auto 0;
}

@media (min-width: 992px) {

  .service-box {
    margin: 20px auto 0;
  }

}

.service-box p {
  margin-bottom: 0;
}

.portfolio-box {
  position: relative;
  display: block;
  max-width: 650px;
  margin: 0 auto;
}

.portfolio-box .portfolio-box-caption {
  color: white;
  opacity: 0;
  display: block;
  background: rgba(240, 95, 64, 0.9);
  position: absolute;
  bottom: 0;
  text-align: center;
  width: 100%;
  height: 100%;
  -webkit-transition: all 0.35s;
  -moz-transition: all 0.35s;
  transition: all 0.35s;
}

.portfolio-box .portfolio-box-caption .portfolio-box-caption-content {
  width: 100%;
  text-align: center;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.portfolio-box .portfolio-box-caption .portfolio-box-caption-content .project-category,
.portfolio-box .portfolio-box-caption .portfolio-box-caption-content .project-name {
  font-family: 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
  padding: 0 15px;
}

.portfolio-box .portfolio-box-caption .portfolio-box-caption-content .project-category {
  text-transform: uppercase;
  font-weight: 600;
  font-size: 14px;
}

.portfolio-box .portfolio-box-caption .portfolio-box-caption-content .project-name {
  font-size: 18px;
}

.portfolio-box:hover .portfolio-box-caption {
  opacity: 1;
}

.portfolio-box:focus {
  outline: none;
}

@media (min-width: 768px) {

  .portfolio-box .portfolio-box-caption .portfolio-box-caption-content .project-category {
    font-size: 16px;
  }

  .portfolio-box .portfolio-box-caption .portfolio-box-caption-content .project-name {
    font-size: 22px;
  }

}

.call-to-action h2 {
  margin: 0 auto 20px;
}

.text-primary {
  color: #F05F40;
}

.no-gutter > [class*='col-'] {
  padding-right: 0;
  padding-left: 0;
}

.btn-default {
  color: #222222;
  background-color: white;
  border-color: white;
  -webkit-transition: all 0.35s;
  -moz-transition: all 0.35s;
  transition: all 0.35s;
}

.btn-default:hover,
.btn-default:focus,
.btn-default.focus,
.btn-default:active,
.btn-default.active,
.open > .dropdown-toggle.btn-default {
  color: #222222;
  background-color: #f2f2f2;
  border-color: #ededed;
}

.btn-default:active,
.btn-default.active,
.open > .dropdown-toggle.btn-default {
  background-image: none;
}

.btn-default.disabled,
.btn-default[disabled],
fieldset[disabled] .btn-default,
.btn-default.disabled:hover,
.btn-default[disabled]:hover,
fieldset[disabled] .btn-default:hover,
.btn-default.disabled:focus,
.btn-default[disabled]:focus,
fieldset[disabled] .btn-default:focus,
.btn-default.disabled.focus,
.btn-default[disabled].focus,
fieldset[disabled] .btn-default.focus,
.btn-default.disabled:active,
.btn-default[disabled]:active,
fieldset[disabled] .btn-default:active,
.btn-default.disabled.active,
.btn-default[disabled].active,
fieldset[disabled] .btn-default.active {
  background-color: white;
  border-color: white;
}

.btn-default .badge {
  color: white;
  background-color: #222222;
}

.btn-primary {
  color: white;
  background-color: #F05F40;
  border-color: #F05F40;
  -webkit-transition: all 0.35s;
  -moz-transition: all 0.35s;
  transition: all 0.35s;
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary.focus,
.btn-primary:active,
.btn-primary.active,
.open > .dropdown-toggle.btn-primary {
  color: white;
  background-color: #ee4b28;
  border-color: #ed431f;
}

.btn-primary:active,
.btn-primary.active,
.open > .dropdown-toggle.btn-primary {
  background-image: none;
}

.btn-primary.disabled,
.btn-primary[disabled],
fieldset[disabled] .btn-primary,
.btn-primary.disabled:hover,
.btn-primary[disabled]:hover,
fieldset[disabled] .btn-primary:hover,
.btn-primary.disabled:focus,
.btn-primary[disabled]:focus,
fieldset[disabled] .btn-primary:focus,
.btn-primary.disabled.focus,
.btn-primary[disabled].focus,
fieldset[disabled] .btn-primary.focus,
.btn-primary.disabled:active,
.btn-primary[disabled]:active,
fieldset[disabled] .btn-primary:active,
.btn-primary.disabled.active,
.btn-primary[disabled].active,
fieldset[disabled] .btn-primary.active {
  background-color: #F05F40;
  border-color: #F05F40;
}

.btn-primary .badge {
  color: #F05F40;
  background-color: white;
}

.btn {
  font-family: 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
  border: none;
  border-radius: 300px;
  font-weight: 700;
  text-transform: uppercase;
}

.btn-xl {
  padding: 15px 30px;
}

::-moz-selection {
  color: white;
  text-shadow: none;
  background: #222222;
}

::selection {
  color: white;
  text-shadow: none;
  background: #222222;
}

img::selection {
  color: white;
  background: transparent;
}

img::-moz-selection {
  color: white;
  background: transparent;
}

body {
  webkit-tap-highlight-color: #222222;
}

我终于成功了!首先,我从新开始,创建了一个新的 Rails 应用程序,因为我处于绝望模式,并安装了许多 Gems 并更改了代码,最后代码变得一团糟。

这次我采取了不同的方法,我没有使用任何额外的 gem,并且我手动安装了所有必要的插件,这意味着只需将所有文件复制并粘贴到正确的目录中并将它们链接在一起。 我必须删除 javascript 目录中的 CoffeeScript 文件,因为该文件引起了一些问题。正如您所看到的,我还必须在 body 标记内手动放置一个触发器,否则 ScrollSpy 函数将无法工作(data-spy="scroll" data-target=".navbar-fixed-top")。由于某种原因,Javascript 仍然无法工作,但我读到,如果未以正确的顺序正确加载,Javascript/jQuery 可能会导致一些问题。所以我删除了 //= require_tree 。在 JavaScript 文件中。并将每个 javascript 按正确的顺序排列。我可以通过查看工作模板的源代码来找出正确的顺序。但还是没有成功!然后,我将“ true %>”放在标记的最末尾,以便 javascript 最后加载。 ...终于成功了!我的下一步是删除 application.js 文件中的 Turbolinks 行,我将更改:

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %> 

into

<%= stylesheet_link_tag    'application', media: 'all' %>

因为我读到 Turbolinks 可能会导致 javascript 的资产管道出现一些问题,尤其是这样。

application.html.erb

<!DOCTYPE html>
<html lang="en">
  <head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Creativetemplate</title>
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>

  </head>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

  <body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">

  <%= render 'layouts/header' %>
  <%= yield %>
  <%= render 'layouts/footer' %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  </body>
</html>

应用程序.js

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require jquery.easing
//= require scrollreveal
//= require jquery.magnific-popup
//= require welcomes

欢迎.js

(function($) {
    "use strict"; // Start of use strict
    // debugger
    // jQuery for page scrolling feature - requires jQuery Easing plugin
    $('a.page-scroll').bind('click', function(event) {
        var $anchor = $(this);
        $('html, body').stop().animate({
            scrollTop: ($($anchor.attr('href')).offset().top - 50)
        }, 1250, 'easeInOutExpo');
        event.preventDefault();
    });

    // Highlight the top nav as scrolling occurs
    $('body').scrollspy({
        target: '.navbar-fixed-top',
        offset: 51
    });

    // Closes the Responsive Menu on Menu Item Click
    $('.navbar-collapse ul li a').click(function() {
        $('.navbar-toggle:visible').click();
    });

    // Offset for Main Navigation
    $('#mainNav').affix({
        offset: {
            top: 100
        }
    })

    // Initialize and Configure Scroll Reveal Animation
    window.sr = ScrollReveal();
    sr.reveal('.sr-icons', {
        duration: 600,
        scale: 0.3,
        distance: '0px'
    }, 200);
    sr.reveal('.sr-button', {
        duration: 1000,
        delay: 200
    });
    sr.reveal('.sr-contact', {
        duration: 600,
        scale: 0.3,
        distance: '0px'
    }, 300);

    // Initialize and Configure Magnific Popup Lightbox Plugin
    $('.popup-gallery').magnificPopup({
        delegate: 'a',
        type: 'image',
        tLoading: 'Loading image #%curr%...',
        mainClass: 'mfp-img-mobile',
        gallery: {
            enabled: true,
            navigateByImgClick: true,
            preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
        },
        image: {
            tError: '<a href="%url%">The image #%curr%</a> could not be loaded.'
        }
    });

})(jQuery); // End of use strict

应用程序.css.scss

/*
*= require magnific-popup
*= require welcomes
*/

@import "bootstrap";
@import "font-awesome";

html,
body {
  height: 100%;
  width: 100%;
}

...
...
...

如果有人对 Javascript 和资产管道有类似的问题,我会尝试解决这个问题:

1)确保所有文件都位于正确的目录中

2)检查 application.css.scss、application.js 和 application.html.erb 中的所有文件是否正确链接在一起

3)删除“//= require_tree”。 application.js 中的行,因为它加载 JavaScript 时没有特定的顺序,并且可能会产生一些问题。按照主题的正确顺序手动键入每一行。您可以通过在浏览器中查看模板的源代码来检查顺序是否正确。

4)通过在运行本地服务器时比较源代码并检查网站与模板网站来检查是否安装了正确版本号的插件。

5)如果您不需要 javascript 目录中的 CoffeeScript 文件,请将其删除。

6)将“javascript_include_tag”从 head 标签内部移至结束 body 标签的正上方。所以 JavaScript 可以最后加载。

7)摆脱 application.js 和 application.html.erb 中的涡轮链接。

8)如果仍然无法正常工作,请检查网站 Chrome 中的开发人员工具(控制台),您还可以在 javascript 文件中使用调试器来查看是否有任何错误。

希望它能帮助某人。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JavaScript 无法通过 Rails 中的引导模板运行 的相关文章

  • 可以使用 jQuery 或 Javascript 将图片的特定部分用作链接吗?

    我有这个想法 将图片 而不是文本 的各个部分链接到不同的页面或网站 并且我想在不实际创建不同的照片并将它们彼此靠近的情况下完成 这样看起来就像是一张完整的图片 这里有人知道如何使用 JavaScript 的变体 例如 jQuery 或纯 J
  • 从未用 @flow 标记的导入文件中获取类型定义

    TL DR我怎么告诉flow从未声明的导入模块导入类型定义 flow 加长版 流接缝能够从不使用流语法的文件中派生类型 请参阅示例 示例文件 flow js if Math random lt 0 5 var y hello else va
  • 标签获取 href 值

    我有以下 html div class threeimages a img alt Australia src Images Services 20button tcm7 9688 gif a div class text h2 a hre
  • JavaScript 重定向到新窗口

    我有以下代码 它根据下拉列表的值重定向到页面 我如何使其在新窗口中打开 function goto form var index form select selectedIndex if form select options index
  • 如何以编程方式处理 JqGrid 事件?

    我正在使用JqG rid 的 ASP NET 包装器 http www trirand net demoaspnet aspx 我想以编程方式连接一些网格的处理程序events http www trirand com jqgridwiki
  • jQuery Mobile 表单验证

    我有一个移动网站 除了验证之外一切都工作正常 基本上我希望从用户那里获取值 然后在单独的页面 process php 上处理它们 但是 在这样做之前 我需要检查以确保字段已填充 我已经研究了几种方法来做到这一点 但似乎没有一种有效 我现在有
  • Gem 在 irb 中可用,但在 Rails 控制台中不可用

    我正在尝试在我的 Rails 项目中使用 RedCloth gem 当我使用irb我可以加载宝石 require rubygems require RedCloth 它工作正常 但是当我在 Rails 控制台中尝试相同的操作时 我收到一条错
  • 使用 KnockoutJs 映射插件进行递归模板化

    我正在尝试使用以下方法在树上进行递归模板化ko映射 插入 http knockoutjs com documentation plugins mapping html 但我无法渲染它 除非我定义separate每个级别的模板 在以下情况下
  • Firefox 书签探索未超过 Javascript 的第一级

    我已经编写了一些代码来探索我的 Firefox 书签 但我只获得了第一级书签 即我没有获得文件夹中的链接 e g 搜索引擎 雅虎网站 谷歌网站 在此示例中 我只能访问 Search engines 和 google com 不能访问 yah
  • 提交表单并重定向页面

    我在 SO 上看到了很多与此相关的其他问题 但没有一个对我有用 我正在尝试提交POST表单 然后将用户重定向到另一个页面 但我无法同时实现这两种情况 我可以获取重定向或帖子 但不能同时获取两者 这是我现在所拥有的
  • Angular 2+ 安全性;保护服务器上的延迟加载模块

    我有一个 Angular 2 应用程序 用户可以在其中输入个人数据 该数据在应用程序的另一部分进行分析 该部分仅适用于具有特定权限的人员 问题是我们不想让未经授权的人知道how我们正在分析这些数据 因此 如果他们能够在应用程序中查看模板 那
  • 如何判断 jquery 对话框是否打开? [复制]

    这个问题在这里已经有答案了 寻找通用案例解决方案来确定当前是否打开任何 jquery 对话框 有多个 试过 ui dialog content dialog isOpen true ui dialog dialog isOpen true
  • 为什么在 Internet Explorer 中访问 localStorage 对象会引发错误?

    我正在解决一个客户端问题 Modernizr 意外地没有检测到对localStorageInternet Explorer 9 中的对象 我的页面正确使用 HTML 5 文档类型 并且开发人员工具报告该页面具有 IE9 的浏览器模式和 IE
  • 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js)Vue Js

    我从 GitHub 下载了一个我和我的朋友正在开发的项目 但是当我尝试运行时 npm run serve 我收到这个错误 src main js 中的错误 Module build failed from node modules babe
  • 有没有办法阻止 prettier / prettier-now 将函数参数分解为新行

    当使用 prettier prettier now 在保存时进行格式化时 当一个函数包装另一个函数时 它会中断到一个新行 我想知道是否有办法阻止这种行为 例如 期望的输出 app get campgrounds id catchAsync
  • 条件在反应本机生产中失败,但在开发中有效

    我创建了一个反应本机应用程序 我需要通过它进行比较 如果属实 就会执行死刑 问题是 该条件适用于 React Native 开发模式 而不适用于 React Native 生产版本 我使用 firebase 作为数据库 也使用 redux
  • 如何在jquery中以相反的顺序迭代元素? [复制]

    这个问题在这里已经有答案了 我是jquery的新手 我想知道如何使用each 在jquery中以相反的顺序迭代表单元素 任何帮助 将不胜感激 尝试这个 input get reverse each function
  • “heroku”命令存在于以下 Ruby 版本中:

    我在使用 heroku 工具带时遇到了重大问题 我正在使用 cedar 14 堆栈 当我尝试使用不是的 ruby 版本时ruby 2 0 0 dev我收到这个错误 rbenv heroku command not found The her
  • 如何在 pg-promise 中设置模式

    我正在搜索的文档pg 承诺 https github com vitaly t pg promise特别是在创建客户端时 但我无法找到设置连接中使用的默认架构的选项 它始终使用public架构 我该如何设置 通常 为数据库或角色设置默认架构
  • fullCalendar 未显示正确的结束日期

    我正在看调试页面 http jsbin com wukofacaxu edit js outputFullCalendar 官方网站的 我想安排一个活动时间为 22 09 2015 至 30 09 2015 dd mm yyyy 但它只显示

随机推荐

  • 地理围栏:如何使用 Oracle Spatial 查找点或形状是否在多边形内

    如何使用 Oracle 空间 SQL 查询查找点或多边形是否在另一个多边形内 这是场景 我有一个表 STATE TABLE 其中包含一个空间类型 sdo geometry 它是一个多边形 比如说一个州 我有另一个表 UNIVERSITY T
  • 使用从多个表中选择的内容创建烧瓶表单

    我看过大量的教程 这些教程显示了使用 Flask 和 flash wtf 的登录表单 但没有一个教程是从数据库表值填充多个选择框的 这就是我正在尝试做的 一个简单的注册表 名 姓 地址第一行 地址行 2 City 状态 Id 从 Id 状态
  • Grails:在某些路径上禁用 Spring Security Core

    如何设置 Spring Security Core 以不过滤对特定模式 例如 api 的调用 grails plugins springsecurity filterChain chainMap api JOINED FILTERS 不起作
  • 确定当前调用堆栈(用于诊断目的)

    出于诊断目的 我有时需要存储导致给定状态转换的调用堆栈 例如授予锁 提交事务等 以便以后出现问题时我可以找出最初触发状态转换的人 目前 我知道检索调用堆栈的唯一方法类似于以下代码片段 我认为它非常丑陋 StackTraceElement c
  • 将 SKSpriteNode 移动到触摸位置

    上面是我的游戏的图像 一个自上而下的游戏 无论玩家触摸屏幕上的哪个位置 我都希望子弹在一段时间内到达该位置 我还希望玩家能够在屏幕上拖动手指 同样的事情也会发生 这样玩家就不必每次想要射击时都触摸屏幕 到目前为止我已经尝试了一些不同的东西
  • IE 安全设​​置设置为高 - javascript 不起作用

    一旦我将 IE 安全设 置设置为高 页面上的 javascript 就会停止执行 它不会抛出错误或任何东西 甚至警报也不起作用 如果我将安全设置设置回中等 一切都会正常进行 有人经历过这样的事情吗 此行为是设计使然 The High安全设置
  • Android 日期选择器 API 级别 11 之前的最小最大日期

    我试图将 Android 中日期选择器的最小和最大日期设置为 API 级别 11 之前 我使用了以下代码 mDatePickerField startDatePickerDialog getClass getDeclaredField mD
  • 在 Apache Felix OSGI 中安装并运行 Web 管理控制台

    我正在尝试在 Apache Felix 4 2 1 中安装并运行 Apache Felix Web 管理控制台 4 2 0 但它不起作用 我已经安装了 Felix Http Jetty 2 2 1 捆绑包 Felic Configurati
  • Internet Explorer 和 Edge 中的视频、内存管理问题,导致页面上的许多视频显示暗/黑和/或无法播放

    我们有一个页面包含 77 个左右的视频缩略图 当视频缩略图悬停在上方时 视频开始在缩略图空间内播放 当许多 8 到 60 个 具体取决于系统 浏览器 悬停在它们上方时 就会出现问题 视频开始播放不正确或不播放 基本上 平坦 冗余区域全部变暗
  • 如何从 CreateProcessWithLogonW 获取标准输出?

    我正在使用来自的代码http www pinvoke net default aspx advapi32 createprocesswithlogonw 如何从标准输出获取字符串形式的输出 就像您在命令窗口中交互运行它时显示的内容一样 ca
  • 如何使用 jQuery 以编程方式触发链接点击?

    如何使用 jQuery 以编程方式触发链接点击 your link id click 看看优秀的jquerydocs了解更多信息
  • MySQL 相当于 PostgreSQL 的 dblink 模块?

    PostgreSQL 的dblink模块允许编写针对远程 PostgreSQL 数据库执行其他 SQL 语句的 SQL 语句 MySQL 中是否有相当于 PostgreSQL 的 dblink 的工具 不完全是 然而 有FEDERATED存
  • 在 python 中,如何将 c++ 共享库的 stdout 捕获到变量

    由于其他一些原因 我使用的 C 共享库将一些文本输出到标准输出 在 python 中 我想捕获输出并保存到变量 关于重定向标准输出有很多类似的问题 但在我的代码中不起作用 例子 抑制模块调用外部库的输出 1 import sys 2 imp
  • Symfony2 - Doctrine2:跨数据库连接列抛出映射异常

    您好 想要在两个实体之间建立连接 这些实体位于不同的数据库中 这是我设置数据库配置的方法 doctrine dbal default connection default connections default driver databas
  • 如何在 jQuery 悬停菜单上允许默认子菜单

    这要从一个相关问题 在得到一个出色的答案后 我遇到了一个不可预见的功能差距 如何显示默认打开的菜单 更具体地说 如果用户登陆我的子导航中存在的页面 我希望打开该子导航并突出显示当前页面 如果他们使用菜单浏览 菜单会相应更改 但如果他们不进行
  • 如何有效地仅读取文本文件的最后一行

    需要从大日志文件中获取最后一行 最好的方法是什么 您想使用向后读取文件ReverseLineReader 如何在C 中使用迭代器反向读取文本文件 然后运行 Take 1 on it var lines new ReverseLineRead
  • 将标注添加到 Highcharts - 堆叠栏

    我正在尝试使用来自的堆叠条形图制作年龄时间表高图表 我想要有多个指向时间线中数据点的调用 我本来打算使用工具提示 但我需要始终显示所有工具提示 并且每个工具提示需要不同的内容 所以我认为使用呼叫会是更好的解决方案 如何确保我的标注指向我需要
  • 无法使用 OpenSSL 的 ssl.SSLContext() 在 Python 客户端中接收对等证书

    我是 Windows 用户 我用Python 3 6 5我导入这个版本的 OpenSSLOpenSSL 1 0 2k 我需要为 python TLS 客户端编写一个脚本 我可以根据支持的 TLS 版本 密码套件和其他配置进行自定义 客户端应
  • 为什么节点 REPL 中未定义 __dirname?

    从节点手册中我看到我可以使用以下命令获取文件的目录 dirname 但从 REPL 来看 这似乎是未定义的 这是我的误解还是错误在哪里 node gt console log dirname ReferenceError dirname i
  • JavaScript 无法通过 Rails 中的引导模板运行

    我创建了一个新的 Rails 应用程序并安装了所有必要的 gem 添加了所有文件 更新了 application js 文件 一切正常 但由于某种原因 所有与 javascript 相关的东西都不起作用 我使用这个模板 https star