Getting Masonry jQuery to Load in Rails App

First time playing with JS/jQuery. I am having trouble getting Masonry to work on my rails project. The script does not appear to be loading. I understand that we don't have to load up jQuery since it comes with Rails default.

index.html.erb

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

<script>
var $container = $('#allreview_container_reviewindex');
$container.imagesLoaded(function(){
  $container.masonry({
    itemSelector : '.eachreview_container_reviewindex',
   // columnWidth : 240
  });
});
</script>

<% if !@reviews.blank? %>
  <div id="allreview_container_reviewindex">
  <% @reviews.each do |review| %>
    <div class="eachreview_container_reviewindex">
       //Image + text
    </div>            
  <% end %>
  </div>
<% end %>

Gemfile

gem 'jquery-rails'

assets/javascripts/jquery.masonry.min.js

//I copied the source from http://masonry.desandro.com/

Any idea where I'm goofing up?

Edit: I checked to make sure that the jquery.masonry.min.js is being loaded through asset pipeline - it's loading but script isn't working to give me that Pinterest layout.

Answers


Got it to work. Had to enclosed the script like so:

$(function () {
  var $container = $('#allreview_container_reviewindex');
    $container.imagesLoaded(function(){
      $container.masonry({
       itemSelector : '.eachreview_container_reviewindex',
       //columnWidth : 240
    });
  });
});

Need Your Help

How can I build an ANTLR Works style parse tree?

antlr antlr3

I've read that you need to use the '^' and '!' operators in order to build a parse tree similar to the ones displayed in ANTLR Works (even though you don't need to use them to get a nice tree in AN...

How do I extract numbers from a string into multiple variables?

python python-3.x

I'm trying to extract this string into numbers based on there location. Heres my code.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.