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'
end
end
...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>In practice, one simply only needs to replace:
<%= render partial: 'user_row', locals: {user: @user} %>
with:
<%= sync partial: 'user_row', resource: @user %>
--
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 rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2ab24f0c-2471-40e8-857c-eda0a66a1642%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.