Lets take for example albums of pictures. If I have a scaffold for
each, and I’m showing an album, what if I want to list all of the
pictures that are in the album?
Surely, I’d want to call the List action in the picture controller.
render_component would do this perfectly. But we’re told not to use
render_component. So instead, I’ll have to put picture list as a
partial… that means I’ll have to do the sql find for the @pictures in
the Album controller…?
its not people don’t like them, but just don’t use them everywhere
because
they are slow. Using render_component is like making another request.
using partials is better as they are faster.
Lets take for example albums of pictures. If I have a scaffold for
each, and I’m showing an album, what if I want to list all of the
pictures that are in the album?
Surely, I’d want to call the List action in the picture controller.
render_component would do this perfectly. But we’re told not to use
render_component. So instead, I’ll have to put picture list as a
partial… that means I’ll have to do the sql find for the @pictures in
the Album controller…?
If you think that your application logic will be cleaner, and you can
reuse
them at multiple places, even from outside the application, then use a
render_component.
Surely, I’d want to call the List action in the picture controller.
render_component would do this perfectly. But we’re told not to use
render_component. So instead, I’ll have to put picture list as a
partial… that means I’ll have to do the sql find for the @pictures in
the Album controller…?
-Ben L.
Ben:
Actually, if an Album has_many photos, then it’s a matter of doing this
in
your controller:
def list @album = Album.find(params[:id], :include=>[:photos] @photos = @album.photos
end
This gets you the album AND its photos in one database call.
Then in your view, you render the partial
<%=render :partial =>"/shared/photos" %>
Partials are definitely the way to go for most of this stuff. I had
component rendering going on in one of my earlier projects and I started
noticing some pretty nasty performance problems. I refactored several of
those into partials, and others I left in, but I made sure to use
fragment
and action caching wherever I could to improve performance.
-----Mensagem original-----
De: [email protected]
[mailto:[email protected]] Em nome de Romeu Henrique
Capparelli F.
Enviada em: quarta-feira, 16 de agosto de 2006 17:36
Para: [email protected]
Assunto: [Rails] acts_as_tree: creating the first element
Hi,
I have a acts_as_tree model but I'm not able to create the first
item without a parent.
With this model:
class Node < ActiveRecord::Base
acts_as_tree
end
I run:
n = Node.new
n.name = ‘my node’
n.save
I get this error
ActiveRecord::RecordNotFound: Couldn't find Subsystem without an ID
from