[Rails] Re: How to use a class, put it inside a model?
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 (http://en.wikipedia.org/wiki/
Singleton_pattern)
On Sep 30, 11:37 pm, Lasse <lasseca...@gmail.com> wrote:
> 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.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home