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

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -