Topic: Dynamic content for layouts

I need to display some things on pretty much every page (like a list of RSS feeds in the right side-bar).  Some of this content is dynamic and needs to be recomputed with each page render.  I have moved the view components into the layout, but I am curious about what to do with the controller code that refreshes the data.

Here are some ideas I've had (using RSS display):

1. Create a helper function (refresh_rss) and call it in a :before_filter
2. Create the refresh_rss and call it manually from the actions where it is necessary
3. Call the refresh_rss from the layout view
4. Others..?

I'm just wondering what other people are doing for this sort of thing.  I'm sure this is a very common problem of displaying multiple unrelated data streams on a single page.

If there is a post/website/blog entry/whatever that answers my questions, please don't hesitate to simply post a link.  I know it can get old fast to answer the same question hundreds of times...

Re: Dynamic content for layouts

Usually a helper method is a good solution for this. That way you can keep it out of the controller entirely.

# in ApplicationHelper
def display_rss # give it a better name
  # fetch RSS data
  render :partial => 'rss_display' # pass rss data
end

You can then call this from any view/layout (<%= display_rss %>)

Railscasts - Free Ruby on Rails Screencasts

Re: Dynamic content for layouts

Ok, that's kind of what I thought.  I haven't written helper methods before.  I always put "helper code" into the lib directory, but I'll give this a shot.

If there is a post/website/blog entry/whatever that answers my questions, please don't hesitate to simply post a link.  I know it can get old fast to answer the same question hundreds of times...