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 https://github.com/chrismccord/sync


On Mon, Dec 15, 2014 at 9:56 AM, Jacob Tarr <[email protected]> wrote:
>
> 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 Hartl'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
> https://github.com/jacobtarr/lemur
>
> 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") %>
>     <div class="dashboard">
>         <aside class="dashboard__sidebar">
>             <%= render 'shared/dashboard/current_user_info' %>
>             <%= render 'shared/dashboard/account_settings' %>
>         </aside>
>         <section class="dashboard__content">
>             <%= render 'shared/dashboard/post_widget' %>
>             <%= render 'shared/dashboard/feed' %>
>         </section>
>     </div><% 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*
>
> <div class="dashboard__content--feed-section">
>     <div class="pagelet">
>         <div class="pagelet__header"><i class="fa fa-rss"></i>Your Feed</div>
>         <div class="pagelet__body">
>             <% if @feed_items.any? %>
>                 <ul class="posts-list">
>                     <%= sync partial: 'micropost', collection: @feed_items %>
>                     <%= sync_new partial: 'micropost', resource: 
> Micropost.new %>
>                 </ul>
>               <%= will_paginate @feed_items %>
>             <% end %>
>         </div>
>     </div></div>
>
> *app/views/sync/microposts/_micropost.html.erb*
>
> <li class="post" id="post-<%= micropost.id %>">
>     <div class="post__avatar">
>         <%= link_to gravatar_for(micropost.user, size: 100), micropost.user %>
>         <span><%= link_to at_username micropost.user %></span>
>     </div>
>     <article class="post__content">
>         <h6><%= micropost.headline %></h6>
>         <p><%= micropost.content %></p>
>     </article>
>     <ul class="post__meta-info">
>         <li><i class="fa fa-clock-o"></i><%= 
> time_ago_in_words(micropost.created_at) %> ago</li>
>         <li><i class="fa fa-calendar-o"></i><%= I18n.l micropost.date, 
> :format => :default %></li>
>         <li><i class="fa fa-map-marker"></i><%= micropost.location %></li>
>         <li class="post__meta-info--delete">
>         <% if current_user?(micropost.user) %>
>             <%= link_to '<i class="fa fa-trash-o"></i>Delete'.html_safe, 
> micropost,
>                                              remote: true,
>                                              method: :delete,
>                                              data: { confirm: "You sure?" } %>
>         <% end %>
>         </li>
>     </ul></li>
>
>
> *app/views/shared/dashboard/_post_widget.html.erb*
>
> <div class="dashboard__content--post-section">
>     <div class="pagelet">
>         <div class="pagelet__header"><i class="fa fa-pencil"></i>Post</div>
>         <div class="pagelet__body">
>             <%= form_for @micropost, html: { class: "post-section__form" }, 
> remote: true do |f| %>
>                 ...
>                 <%= f.submit "Post", class: "btn btn__primary btn__lg 
> btn__post" %>
>             <% end %>
>         </div>
>     </div></div>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/2ab24f0c-2471-40e8-857c-eda0a66a1642%40googlegroups.com
> <https://groups.google.com/d/msgid/rubyonrails-talk/2ab24f0c-2471-40e8-857c-eda0a66a1642%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAFKVRj-NnJuapbJ6vQctpJ0uMc_xhaGvL4dRW2dmHv-dMmGOZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to