Bad URI on rails javascript_include_tag and stylesheet_link_tag

此生再无相见时 提交于 2019-12-24 04:29:44

问题


So I took a few months out from this project, went to it today and tried to host it, and without touching anything I am getting a bad URI error on two links to my javascript and css.

<%= javascript_include_tag "application", "data-turbolinks-track": "reload" %>

<%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track": "reload" %>

Those are the two pieces of code causing the errors. Does anyone know what the problem could be, I have tried all combinations of double/single quotes but to no avail.

Any help will be much appreciated!

Edit:

Application.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. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//= require jquery-ui




$(window).scroll(function() {
    var distanceFromTop = $(this).scrollTop();
    if (distanceFromTop >= $('.navbar').height()) {
        $('#sticky').fadeIn('1000').addClass('fixed');
    } else {
        $('#sticky').removeClass('fixed');
    }
});



$(document).ready(function() {
    $(".dropdown-toggle").dropdown();
});

Application.css

    /*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
 * files in this directory. Styles in this file should be added after the last require_* statement.
 * It is generally better to create a new file per style scope.
 *
 *= require_tree .
 *= require_self
 *= require jquery-ui
 */

body {
    font-family: sans-serif;
    background-color: white;
    color: #686868;
}

@media (min-width: 768px) and (max-width: 991px) {
    .navbar-collapse.collapse {
        display: none !important;
    }
    .navbar-collapse.collapse.in {
        display: block !important;
    }
    .navbar-header .collapse, .navbar-toggle {
        display:block !important;
    }
    .navbar-header {
        float:none;
    }




}



* {
    border-radius: 0;
}

.navbar{
    -webkit-border-radius: 0;
    -moz-border-radius: 0;
    border-radius: 0;
}

.navbar .navbar-nav {
    display: inline-block;
    float: none;
    vertical-align: top;
    margin-left: auto;
    padding: 0;
}

.navbar .navbar-collapse {
    text-align: center;
    border-radius: 0;
}

a {
    color: #1b7b90;
}

a:hover {
    color: #1b7b90;
    text-decoration: none;
}

hr {
    border: 0;
    height: 1px;
    background: #333;
    background-image: linear-gradient(to right, #ccc, #333, #ccc);
}

.property-link:hover {
    color: white;
}

.property-fixedbar {
    color: white;
    text-align: center;
    border-style: solid;
    border-width: 1px;
    border-color: white;
    margin-top: 12px;
    padding-top: auto;
}

.property-fixedbar:hover {
    color: #1b7b90;
    background-color: white;
}

.main-content {
    color: #686868;
}

.search-button:hover {
    background-color: black;
}

.table th{
    text-align: center;
}

#sticky {
    z-index: 10;
    height: 67px;
}


#sticky.fixed {
    display: block;
    position: fixed;
    top: 0;
    width: 100%;
}

.navBar-wrapper {
    height: 67px;
}

@media (min-width: 10px) and (max-width: 991px) {
    .navBar-wrapper {
        height: 150px;
    }

    #sticky {
        height: 100px;
    }

    #show-top {
        height: 180px;
    }

    #sticky.fixed {
        position: relative;
    }

    .fixed-summary {
        position: absolute;
        margin: 0;
    }
    .thumbnail-images {
        display: none;
    }
}

.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
    margin: auto;
}

#myCarousel {
    margin-left: 30px;
    margin-right: 30px;
}

.carousel-control {
    padding-top: 25%;
}
.carousel-control.left, .carousel-control.right {
    background: none;
    color: #1b7b90;
    border: none;
}

.hide-bullets {
    list-style:none;
    margin-left: 0;
    margin-top:20px;
}

.thumbnail {
    padding: 0;
}

.carousel-inner>.item>img, .carousel-inner>.item>a>img {
    width: 100%;
}

.green {
    color: green;
}

.red {
    color: red;
}

回答1:


I had exactly the same error and it drove me nuts.

I'm guessing this has something to do with the URI (duh!) and I finally moved my project folder out of Google Drive to my desktop, running bundle, rails db:migrate, rails assets:precompile and then rails s. Turns out that fixed it for me.



来源:https://stackoverflow.com/questions/48287113/bad-uri-on-rails-javascript-include-tag-and-stylesheet-link-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!