Forum: Ruby on Rails Custom Non-ActiveRecord Classes or not...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
963e68decf3aa66744de537db2c0ea0a?d=identicon&s=25 Ro (Guest)
on 2006-04-07 22:21
Say I want to gather info from various Models... Files, Folders, and put
them into a 'display' Object DisplayFilesystem that will standarize the
info from both tables (for display only)...

Class DisplayFilesystem
  attr_accessor :item_id, :name, :type, :description, :date
  def initialize
    @item_id = @name = @type = @description = @date = nil
  end
end

So in the code side I will get the info and put it into an array of
objects and send it to the template.

However, these are my Models (assume the DB tables are good):

class Fileset < ActiveRecord::Base
  belongs_to :folder
  belongs_to :datafile
end

class Folder < ActiveRecord::Base
   #acts_as_tree :order => "name",
   #            :counter_cache => true
   has_many  :filesets
   has_many  :datafiles,
             :through => :filesets

   belongs_to  :parent,
               :counter_cache => true,
               :class_name => "Folder"
   has_many    :children,
               :class_name => "Folder",
               :foreign_key => "parent_id",
               :order => "name",
               :dependent => true
end

class Datafile < ActiveRecord::Base
  has_many  :filesets
  has_many  :folders,
            :through => :filesets
end

So my questions are:

1). Is there a better way to do this? If not, WHERE do these custom
classes go?

2). As you can see, I'm using the acts_as_tree (exploded) on my Folder
model... I can get all it's Folder children fine... but I have to get
it's Datafile children separately. Is there a way to get them all in one
object and then that way sending that into the template instead of my
DisplayFilesystem hack?

Sorry but I figured I needed to be verbose. :-/

thanks,

ro
This topic is locked and can not be replied to.