How to use a class, put it inside a model?

class Feeds   FEEDS = %W(     http://feed.kennisnet.nl/Basisonderwijs     http://feed.kennisnet.nl/Voortgezetonderwijs     http://wp.digischool.nl/nieuws/feed/   )

  def load_feeds     @feeds_ds = feeds.first     @feeds = vopo? ? feeds.second : feeds.last   end

  def feeds     @feeds ||= Feedzirra::Feed.fetch_and_parse(FEEDS).values.map { | feed> feed.entries.first(6) }.entries   end

  def vopo?     params[:vopo] == 'po'   end end

This is my class. I would like to display the feeds on every page. Where should i put it? in a model or controller? and how doe i use it?

def load_feeds f = Feeds.new f::feeds f::load_feeds end

This is what my view looks like

<%- for feed in @feeds[0..2] -%> <%= link_to feed.title, feed.url -%> <p><%=h feed.summary[0..60] %>...</p></li> <%- end -%>

Thank you in advance.

I would probably put the class in a file inside lib/ folder and add a helper for displaying the feeds.

<%= feeds_list %>

Daniel Gaytán

1) you should not put it into the any controller, controllers have another purpose, in controller you should only call feeds loading from some other class. 2) I agree to Daniel, you may put it into the lib/ folder or into app/ models 3) The whether should you have a helper or not for rendering this part of the view depends on the whether will you call it from the different places of views (then you definitely should have a helper), or you'll have only one place in say some main layout where you render it then there is no need in helper 4) If you want to see feeds within all your pages you should put the collecting method (load_feeds) into some private/protected method of ApplicationController and then use it as before_filter in your controllers (don't forget to turn it off for e.g. destroy method when you don't need it) 5) you should pass params[:vopo] to your class as some parameter since it's part of controller 6) If you need just to fetch the feeds once per page I'd put the feeds loading into some static method, and later call it just like (my_feeds = Feed.load_feeds), if you need to use them in several places you may also use Singleton pattern (Wikipedia, the free encyclopedia Singleton_pattern)