Search code examples
ruby-on-rails-4eachmailboxer

Rails 4 Index.html.erb loop


So I have the following index for my mailboxer conversations:

conversations/index.html.erb

<p><% @conversations.each do |conversation| %>
 <% conversation.participants.each do |participant| %>
  <% if participant != current_user %>
  From:  <%= participant.name %> <br />
  <% end %>
<% end %>
Subject: <%= link_to conversation.subject %> <br />


Date: <%= conversation.updated_at.strftime("%a, %m/%e/%Y %I:%M %p") %> <br />

<%= link_to "Move to Trash", {:controller => "conversations", :action => "trash", :id => conversation.id}, :title=> "Move to Trash", :method=>'post' %> <br/> </p>
<% end %>

I came around to this because first it was saying there was no local method for "participant" and then it was saying there was no local method for "conversation." So I just made an each.do loop for both of them.

This works... It lists the sender and subject and the option to move each message to a trash folder... but it starts looping about 5 times per second to infinity. (I'm assuming this is hell on the server.)

THEN I noticed that this also happens for the users index.html and edit.html


Solution

  • Figured it out. I'll try to explain the problem and the solution as in-depth as possible.

    1. Load the index.html.erb of a short page (user edit, index... whatever.)
    2. tail the production or development.log file (or just look at the webrick screen
    3. Notice that it's looping over and over and your cpu is heating up.

    Turns out it was some crazy endless_scroll.js that never did anything for anyone... that all-of-a-sudden decided to activate and loop any page it deemed was too short.

    Now the crazy thing (and mind you, I'm typing to myself at this point) is that, if you just threw in some random paragraphs... it would stop. Delete them? It would start looping again. (I guess according to the scroll limit.)

    So I just deleted the endless_scroll.js and did a rake assets:clean and a rake assests:precompile.

    Now everything is back to normal.