admin管理员组文章数量:1333164
I was trying to add a javascript-plugin masonry to my rails app and was wondering why it would only work for my wele controller (localhost:3000/) but not for other controllers as localhost:3000/projects/1, although I'm using exactly the identical code.
I get this error:
GET localhost:3000/projects/assets/jquery.masonry.js 404 (Not Found)
and
Uncaught TypeError: Object [object Object] has no method 'masonry'
(anonymous function)
e.resolveWith jquery.min.js
e.extend.ready jquery.min.js
c.addEventListener.z
I asume I get the error because of the wrong path localhost/projects/assets instead of localhost/assets, but I couldn't find out how to fix this. Any help would be wele!
This is the code in the view:
<% content_for(:scripts) do %>
<script type="text/javascript">
$(function(){
$('.squarescontainer').masonry({
// options
itemSelector : '.item',
isAnimated: true
});
});
</script>
<% end %>
and this is my application.rb:
<!DOCTYPE html>
<html>
<head>
<title>ifub</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<link type="text/css" rel="stylesheet" href="+Sans+Narrow&v1">
<link type="text/css" rel="stylesheet" href=";>
<script src="//ajax.googleapis/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src = "assets/jquery.masonry.js"></script>
<script src = "assets/jquery.masonry.min.js"></script>
<%= yield(:head) %>
</head>
<body>
<%= render 'layouts/logo' %>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<div class="frame">
<div class="container">
<%= yield %>
<%= yield :scripts %>
</div>
</div>
</body>
</html>
Thanks for your help!
I was trying to add a javascript-plugin masonry to my rails app and was wondering why it would only work for my wele controller (localhost:3000/) but not for other controllers as localhost:3000/projects/1, although I'm using exactly the identical code.
I get this error:
GET localhost:3000/projects/assets/jquery.masonry.js 404 (Not Found)
and
Uncaught TypeError: Object [object Object] has no method 'masonry'
(anonymous function)
e.resolveWith jquery.min.js
e.extend.ready jquery.min.js
c.addEventListener.z
I asume I get the error because of the wrong path localhost/projects/assets instead of localhost/assets, but I couldn't find out how to fix this. Any help would be wele!
This is the code in the view:
<% content_for(:scripts) do %>
<script type="text/javascript">
$(function(){
$('.squarescontainer').masonry({
// options
itemSelector : '.item',
isAnimated: true
});
});
</script>
<% end %>
and this is my application.rb:
<!DOCTYPE html>
<html>
<head>
<title>ifub</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<link type="text/css" rel="stylesheet" href="http://fonts.googleapis./css?family=PT+Sans+Narrow&v1">
<link type="text/css" rel="stylesheet" href="http://fonts.googleapis./css?family=Oswald">
<script src="//ajax.googleapis./ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src = "assets/jquery.masonry.js"></script>
<script src = "assets/jquery.masonry.min.js"></script>
<%= yield(:head) %>
</head>
<body>
<%= render 'layouts/logo' %>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<div class="frame">
<div class="container">
<%= yield %>
<%= yield :scripts %>
</div>
</div>
</body>
</html>
Thanks for your help!
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Dec 27, 2012 at 17:54 Daniel ReinerDaniel Reiner 1371 gold badge2 silver badges11 bronze badges1 Answer
Reset to default 2You are using URL relative to current path, so if your page is localhost:3000/project/page.html
, JS url will be localhost:3000/project/assets/...
. Try to change your code like this:
<script src = "/assets/jquery.masonry.js"></script>
<script src = "/assets/jquery.masonry.min.js"></script>
see "/" added before assets. In that case browser will load script relatively to site root.
In that case even if your current page is localhost:3000/project/page.html
, JS URL still will be localhost:3000/assets/...
Besides, you should connect only one version of plugin - minimized or not
本文标签: javascriptGET httplocalhost3000projectsassetsjquerymasonryjs 404 (Not Found)Stack Overflow
版权声明:本文标题:javascript - GET http:localhost:3000projectsassetsjquery.masonry.js 404 (Not Found) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742350618a2458417.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论