chrismccord / render_sync

Real-time Rails Partials
Other
1.4k stars 106 forks source link

Troubleshooting not updating #117

Closed g8d3 closed 10 years ago

g8d3 commented 10 years ago

Hi,

I am building a chat application, and it stopped updating rows in an index view after I wrote some tests, I have:

  1. Restarted both servers, Faye and Rails.
  2. I don't see any output in browser console, faye.js is correctly downloaded in each browser.
  3. I don't see any error in Faye server
  4. I see successful updates in Rails server

This is my MVC:

class Message < ActiveRecord::Base
  sync :all
end

class MessagesController < InheritedResources::Base
  enable_sync

  def permitted_params
    params.permit(:message => [:content])
  end
end

app/views/index.html.slim

h1 Listing messages

table
  tr
    th Content
    th User
    th
    th
    th

  - @messages.each do |message|
    = sync partial: 'row', resource: message

br

= link_to 'New Message', new_message_path

app/views/sync/messages/_row.html.slim

tr
  td = message.content
  td = message.user_id
  td = link_to 'Show', message
  td = link_to 'Edit', edit_message_path(message)
  td = link_to 'Destroy', message , :method => :delete,
    data: {:confirm => 'Are you sure?'}

It is wrapping each row with this code:

<script type="text/javascript" data-sync-id="/15c180912ed85fc2a2d03c1b7a7fc8a90a00400b-start">
            Sync.onReady(function(){
              var partial = new Sync.Partial({
                name:           'row',
                resourceName:   'message',
                resourceId:     '1',
                authToken:      '/15c180912ed85fc2a2d03c1b7a7fc8a90a00400b',
                channelUpdate:  '/15c180912ed85fc2a2d03c1b7a7fc8a90a00400b-update',
                channelDestroy: '/15c180912ed85fc2a2d03c1b7a7fc8a90a00400b-destroy',
                selectorStart:  '/15c180912ed85fc2a2d03c1b7a7fc8a90a00400b-start',
                selectorEnd:    '/15c180912ed85fc2a2d03c1b7a7fc8a90a00400b-end',
                refetch:        false
              });
              partial.subscribe();
            });
          </script>
 -------> row here
<script type="text/javascript" data-sync-id="/15c180912ed85fc2a2d03c1b7a7fc8a90a00400b-end">
          </script>

Any advice to spot the problem is greatly appreciated, thanks.

g8d3 commented 10 years ago

In index, I keep receiving a lot of requests from faye:

screen shot 2014-04-17 at 10 30 19 pm

chrismccord commented 10 years ago

See the current caveats section here: https://github.com/chrismccord/sync#current-caveats

You may need to move the tr from the sync partial to outside in the parent view. Also please run rake tmp:clear and restart your webserver.

g8d3 commented 10 years ago

After making sure my partial was right, rake tmp:clear, and restart servers, I am getting this in browser console:

screen shot 2014-04-18 at 9 25 38 am

It says example, but in my sync.yml I have:

development:
  server: "http://localhost:9292/faye"
...
production:
  server: "http://localhost:9292/faye"

And I am trying running faye in production and development, just in case it's different, but I am having the same result.

Update

I forgot to run rake tmp:clear after changing my sync.yml, now it's working, thanks a lot.