Scott Holland wrote:
I'm setting up a forum and I'm having a sidebar which will display the
recent postings and will be used throughout the site. This sidebar is
part of the application.rhtml layout.
How do I use data from the "forum" controller in this layout when the
layout is used on all of the other controllers across the site?
Could someone point me in the right direction?
Many thanks - when I get a little more advanced I hope I can contribute
as much advice as you guys have so kindly given me
Use a partial (perhaps in a /shared folder) and populate it with an instance variable set up in the application controller using a before_filter.
So something like this
<% @recent_posts.each do |post| %>
<%= post.title %>
<% end %>
in the application controller
@recent_posts = Post.find(:all, :limit => 20, :order => "created_at DESC")
and then in your layout:
render :partial => "/shared/recent_postings_sidebar"