Jquery – Failed to load resource – server responded with a 404 status error in Rails 3 project

jqueryruby-on-railsruby-on-rails-3

I'm trying to load up jquery masonry script in my app, but it's not working.

Upon debugging, I see this error:

Failed to load resource: the server responded with a http://localhost:3000/app/assets/javascripts/jquery.masonry.min.js status of 404 (Not Found)

If I try to access the script directly from my browser via the link http://localhost:3000/app/assets/javascripts/jquery.masonry.min.js I get this error:

No route matches [GET] "/Users/fkhalid2008/loand/app/assets/javascripts/jquery.masonry.min.js"

What am I doing wrong here?

Relevant code is attached below.

Thanks,

Faisal

POSTS>INDEX.HTML.ERB (This is where I am trying to load up the Jquery Masonry script)

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="/app/assets/javascripts/jquery.masonry.min.js">     
</script>

.....

<script type="text/javascript"> 
$('#container').masonry({
  itemSelector: '.box',
   columnWidth : 120 
});
</script>

APPLICATION.JS FILE

//= require jquery
//= require jquery_ujs
//= require jquery.masonry.min
//= require twitter/bootstrap
//= require_tree .

Best Solution

When dealing with assets pipeline, you just need tell the Rails app that the file its in you asset folder. Like:

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

And put the jquery.masonry.min.js at /app/assets/javascripts

Related Question