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’ %>
<% 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
-
<%= sync partial: 'micropost', collection:
@feed_items %>
<%= sync_new partial: 'micropost', resource:
Micropost.new %>
app/views/sync/microposts/_micropost.html.erb
<%= 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