Using the Sync gem to make restful Rails app real-time

I’ve made a functional mini social network app in Rails. I’m using the
Sync
gem in order to make my app realtime so that when a user posts
something,
it’ll immediately show up on their home feed. I feel like I’m extremely
close to making this work. The form works and there are no run-time
errors
with the below code. However, when the current user posts something, it
doesn’t appear on the home page unless the page is refreshed. If it’s
any
help, I’m using Michael H.'s system to do this. What am I doing wrong
here? Thanks for your help in advance. If I missed a piece of code that
I
should I have put here, the repository is on

My code:

app/controllers/microposts_controller.rb


def create
@micropost = current_user.microposts.build(micropost_params)
if @micropost.save
sync_new @micropost
flash[:success] = “Your post has been published!”
else
@feed_items = []
render ‘static_pages/home’
endend

app/views/static_pages/home.html.erb

<% provide(:title, “Home”) %><% if logged_in? %>
<% provide(:main_class_modifier, “–dashboard”) %>




<%= render ‘shared/dashboard/post_widget’ %>
<%= render ‘shared/dashboard/feed’ %>

<% else %>
<% provide(:main_class_modifier, “–homepage”) %>
<%= render ‘static_pages/home/home_features’ %>
<%= render ‘static_pages/home/home_newsletter’ %><% end %>

app/views/shared/dashboard/_feed.html.erb

Your Feed
<% if @feed_items.any? %>
    <%= sync partial: 'micropost', collection: @feed_items %> <%= sync_new partial: 'micropost', resource: Micropost.new %>
<%= will_paginate @feed_items %> <% end %>

app/views/sync/microposts/_micropost.html.erb

  • <%= link_to gravatar_for(micropost.user, size: 100), micropost.user %> <%= link_to at_username micropost.user %>
    <%= micropost.headline %>

    <%= micropost.content %>

    • <%= time_ago_in_words(micropost.created_at) %> ago
    • <%= I18n.l micropost.date, :format => :default %>
    • <%= micropost.location %>
    • <% if current_user?(micropost.user) %> <%= link_to 'Delete'.html_safe, micropost, remote: true, method: :delete, data: { confirm: "You sure?" } %> <% end %>
  • app/views/shared/dashboard/_post_widget.html.erb

    Post
    <%= form_for @micropost, html: { class: "post-section__form" }, remote: true do |f| %> ... <%= f.submit "Post", class: "btn btn__primary btn__lg btn__post" %> <% end %>

    You are not syncing, you are rendering.

    In practice, one simply only needs to replace:

    <%= render partial: ‘user_row’, locals: {user: @user} %>

    with:

    <%= sync partial: ‘user_row’, resource: @user %>

    Look at the sync documentation here GitHub - chrismccord/render_sync: Real-time Rails Partials