簡體   English   中英

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

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

我試圖在我的Rails應用程序中添加一個javascript插件砌體,並且想知道為什么它僅適用於我的歡迎控制器(localhost:3000 /)而不適用於其他控制器,例如localhost:3000 / projects / 1,盡管我使用完全相同的代碼。

我收到此錯誤:

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

未捕獲的TypeError:對象[object Object]沒有方法“砌體”

(匿名功能)

e.resolveWith jquery.min.js

e.extend.ready jquery.min.js

c.addEventListener.z

我猜我是因為錯誤的路徑localhost / projects / assets而不是localhost / assets而收到錯誤,但是我找不到解決方法。 任何幫助都將受到歡迎!

這是視圖中的代碼:

<% content_for(:scripts) do %>
<script type="text/javascript">

  $(function(){
    $('.squarescontainer').masonry({
      // options
      itemSelector : '.item',
      isAnimated: true
    });
  });

</script>
<% end %>

這是我的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>

謝謝你的幫助!

您正在使用相對於當前路徑的URL,因此,如果您的頁面是localhost:3000/project/page.html ,則JS URL將是localhost:3000/project/assets/... 嘗試像這樣更改代碼:

<script src = "/assets/jquery.masonry.js"></script>
<script src = "/assets/jquery.masonry.min.js"></script>

請參閱在資產之前添加“ /”。 在這種情況下,瀏覽器將相對於站點根目錄加載腳本。 在這種情況下,即使您當前的頁面是localhost:3000/project/page.html ,JS URL仍將是localhost:3000/assets/...

此外,您只能連接一個版本的插件-是否已最小化

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM