[Cells-talk] render question

Karl Varga kjvarga at gmail.com
Fri Nov 13 00:41:15 EST 2009


Hi guys,

I've recently started using cells.  It's perfect for what I'm doing,
which is a music player widget.  I started off tentatively using cells
AND presenter classes...then I realized I could just use cells after
reading some of the Cells subclassing magic.  So I did that and it
worked out great.  I had some confusions along the way, mostly around
rendering.  It just didn't work quite as I expected it to.  I started
off avoiding partials, because the source code implies that partials
are BAD...but they're the only thing that worked in the end.  Anyways,
my question is...

I have the following files:

./player/widget:
  collection_cell.rb
  playing_now_collection_cell.rb

  ./player/widget/collection:
    _empty_item.html.haml
    album_item.haml
    artist_item.haml
    collection.html.haml
    playlist_item.html.haml
    track_item.html.haml

  ./player/widget/playing_now_collection:
    _empty_item.html.haml
    track_item.html.haml

The PlayingNowCollection (PNC) is a special type of Collection but it
only needs to override the track_item view.  collection.html.haml is
the view that starts everything off, and it's the same for both
classes, so I only want that in the base class.  In collection.html I
have the following call:

.songs
  = render :partial => 'empty_item' if @show_empty_item

This works.  When displaying a PNC it uses it's _empty_item partial
and when displaying a Collection it uses the collection _empty_item
partial.  Awesome.  The problem is I want similar behaviour but I want
to render a state.  I don't know how to do it without hard-coding the
cell class as in:

  - @items.each do |item|
    = render_cell 'player/widget/collection', :item, :item => item

(BTW it would be great to have render :collection support...)

How can I do this?  render :view => :item doesn't work.  And that's
another problem.  I would expect render :view to first look in the
directory of the Cell class that was instantiated (PNC in this
example), not in the directory that the calling view resides in
(collection).  That's what forced me to use partials, they seem to do
the "right" thing.  But now I'm having the same problem rendering the
state of a subclass from a view in the superclass.

Regards,
Karl

-- 
Karl Varga
kjvarga at gmail.com
Cell: +61 (0)4 2075 1356
Skype: kjvarga


More information about the Cells-talk mailing list