简体   繁体   English

GET http:// localhost:3000 / projects / assets / jquery.masonry.js 404(未找到)

[英]GET http://localhost:3000/projects/assets/jquery.masonry.js 404 (Not Found)

I was trying to add a javascript-plugin masonry to my rails app and was wondering why it would only work for my welcome controller (localhost:3000/) but not for other controllers as localhost:3000/projects/1, although I'm using exactly the identical code. 我试图在我的Rails应用程序中添加一个javascript插件砌体,并且想知道为什么它仅适用于我的欢迎控制器(localhost:3000 /)而不适用于其他控制器,例如localhost:3000 / projects / 1,尽管我使用完全相同的代码。

I get this error: 我收到此错误:

GET localhost:3000/projects/assets/jquery.masonry.js 404 (Not Found) GET localhost:3000 / projects / assets / jquery.masonry.js 404(未找到)

and

Uncaught TypeError: Object [object Object] has no method 'masonry' 未捕获的TypeError:对象[object Object]没有方法“砌体”

(anonymous function) (匿名功能)

e.resolveWith jquery.min.js e.resolveWith jquery.min.js

e.extend.ready jquery.min.js e.extend.ready jquery.min.js

c.addEventListener.z 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. 我猜我是因为错误的路径localhost / projects / assets而不是localhost / assets而收到错误,但是我找不到解决方法。 Any help would be welcome! 任何帮助都将受到欢迎!

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: 这是我的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.com/css?family=PT+Sans+Narrow&v1">
    <link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald">

    <script src="//ajax.googleapis.com/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! 谢谢你的帮助!

You 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/... . 您正在使用相对于当前路径的URL,因此,如果您的页面是localhost:3000/project/page.html ,则JS URL将是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/... 在这种情况下,即使您当前的页面是localhost:3000/project/page.html ,JS URL仍将是localhost:3000/assets/...

Besides, you should connect only one version of plugin - minimized or not 此外,您只能连接一个版本的插件-是否已最小化

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GET http://localhost:3000/dashboard/js/appclient.js net::ERR_ABORTED 404(未找到) - GET http://localhost:3000/dashboard/js/appclient.js net::ERR_ABORTED 404 (Not Found) "GET http:\/\/localhost:3000\/public\/js\/test.js net::ERR_ABORTED 404(未找到)" - GET http://localhost:3000/public/js/test.js net::ERR_ABORTED 404 (Not Found) GET http://localhost:3000/search 404 (Not Found)REACT.JS, Node.js 和 Axios - GET http://localhost:3000/search 404 (Not Found)REACT.JS, Node.js and Axios GET http://localhost:3000/bundle.js net::ERR_ABORTED 404(未找到) - GET http://localhost:3000/bundle.js net::ERR_ABORTED 404 (Not Found) 识别:9 GET http://localhost:3000/script.js net::ERR_ABORTED 404(未找到) - recognition:9 GET http://localhost:3000/script.js net::ERR_ABORTED 404 (Not Found) GET http://localhost:3000/insert.js net::ERR_ABORTED 404(未找到) - GET http://localhost:3000/insert.js net::ERR_ABORTED 404 (Not Found) POST http:// localhost:3000/404(未找到) - POST http://localhost:3000/ 404 (Not Found) React.js / Firebase 应用程序中的 Axios 错误(404):POST http://localhost:3000/login 404(未找到) - Axios error (404) in React.js / Firebase app: POST http://localhost:3000/login 404 (Not Found) GET http://localhost:3000/components/t.mp3 net::ERR_ABORTED 404(未找到) - GET http://localhost:3000/components/t.mp3 net::ERR_ABORTED 404 (Not Found) Angular 2 + angular-in-memory-web-api zone GET http:// localhost:3000 / traceur 404(Not Found) - Angular 2 + angular-in-memory-web-api zone GET http://localhost:3000/traceur 404 (Not Found)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM