Maged Makled Maged Makled - 11 months ago 53
Javascript Question

js.erb working locally but not in production

I followed the tutorial here for an infinite scrolling. The code works good locally but when I deploy it to prod. the pagination links (1 2 3 4) still show and the infinite scrolling doesn't fire. I also tried to add these files in

with no success

First of I'm using
Rails 4
, my
looks like this

//= require jquery2
//= require jquery.turbolinks
//= require jquery_ujs
//= require jquery-ui.min
//= require bootstrap-hover-dropdown.min
//= require bootstrap.min
//= require select2
//= require infinite_scroll
//= require turbolinks

Controller action

respond_to do |format|
format.js { render "visitors/index" }


$('#my-articles').append('<%= j render @articles %>');
<% if @articles.next_page %>
$('.pagination').replaceWith('<%= j will_paginate @articles %>');
<% else %>
<% end %>

function add_tweets(){
<% @articles.each do |article|%>
handle_open_modal("<%= %>");


Answer Source

Here is what I did to get it working

I removed turbolinks and all it's reference

Then added this to the index.html.erb without have to use jQuery $(document).on('ready

if ($('#infinite-scrolling').size() > 0){
        $(window).on('scroll', function(){
          var more_posts_url = $('.pagination .next_page a').attr('href')
          heights = $(document).height() - $(window).height() - 500
            if(more_posts_url && $(window).scrollTop() > heights){
                $('.pagination').html('<img src="/assets/ajax-loader.gif" alt="Loading..." title="Loading..." />')

Then all the *.js.erb start working.

I was trying to avoid removing turbolinks but done trying to get it working with it.