最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - GET http:localhost:3000projectsassetsjquery.masonry.js 404 (Not Found) - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 2

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/.... 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

发布评论

评论列表(0)

  1. 暂无评论