ruby - Rendering a partial with locals -
i've rendered partial loads users latest post in 1 of tab panels.
<div role="tabpanel" class="tab-pane" id="updates_panel"> <%= render :partial => "pages/update_panel", :locals => { :post => @user.latest_post } %> </div>
at first method latest_post display users "last or latest post".
def latest_post posts.order(:created_at => :desc).first end
but realized need display post in descending order , cant seem right.
create method latest_posts
,
def latest_posts posts.order(:created_at => :desc) end def latest_post latest_posts.first end
and use in partal,
<%= render :partial => "pages/update_panel", :locals => { :post => @user.latest_post, :posts => @user.latest_posts } %>
Comments
Post a Comment