I'm having a problem with my javascript and jquery. I'm using bootstrap in addition to some self written scripts. When I attempt a javascript driven action (ie clicking a button that shows a hidden div, or openning a modal), the browser does not respond. The browser's javascript console shows the following errors:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/ecns/css/bootstrap.min.css
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/ecns/js/bootstrap.min.js
Notice that the location is in the folder "ecns" rather than "assets". Ecns is one of my models, the one I currently was working with in my browser, if I go to a different part of my app, the error looks like this:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/requests/js/bootstrap.min.js
I know there is not a problem with the scripts themselves because they work on different computers. I'm assuming I have something in rails either configured or installed incorrectly. For reference, here is my application.js:
//= require jquery
//= require jquery_ujs
//= require_tree .
And the following is in my application layout:
<head>
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<title>Site</title>
<%= javascript_include_tag "application" %>
<%= stylesheet_link_tag "application", media: "all" %>
<%= csrf_meta_tags %>
</head>
<body>
...
<script src="js/bootstrap.min.js"></script>
</body>
Why would rails be looking to the incorrect locations for the assets? I'm running rails 3.2.1
Rails is using a custom asset pipeline, that will make all the assets visible under the assets
subdirectory in the root directory of the app.
So if your base address is http://www.something.com/
all assets will live under http://www.something.com/assets/
.
If you want to import a CSS or a JS file, and if you placed them correctly in the app/assets/
directory in Rails, you should use these commands:
<%= javascript_include_tag "bootstrap.min" %>
<%= stylesheet_link_tag "bootstrap.min" %>
Placing them wherever you need in your layout.
If you still want to import them manually (and I'd not recommend it), use these:
<script src="assets/bootstrap.min.js"></script>
<link href="assets/bootstrap.min.css" rel="stylesheet" media="screen">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.