It''s a quick response to your inheritance problem, so maybe it
won''t
be enough for you, but it may show you a way to resolve your problem.
See the articles (below) about inheritance and db in RoR (you may want
to read the first link first, since it explains what are the different
solutions to inheritance in db and what RoR developpers have chosen)
http://wiki.rubyonrails.com/rails/show/SingleTableInheritance
http://wiki.rubyonrails.com/rails/show/TopicsInheritanceExample
2005/6/24, Michael Koziarski
<koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> On 6/25/05, Claudio Cicali
<c.cicali-dP4/7z9UC85eoWH0uzbU5w@public.gmane.org> wrote:
> >
> > Within my application I have "movies", "books" and
"albums".
> >
> > So, I have three db tables and three models.
> >
> > They all naturally belongs to a generic "media", but
I''ve not
> > a media table.
> >
> > I have a MediaController from which all other controllers
> > inherit from.
> >
> > Question is: could I have a Media model without a "phisical"
> > table? (this should be more of a ''virtual''
superclass)
>
> I''m not an inheritance guy, I''ll leave the answer to that
for someone else
>
> > Addictionally: which the best way to pass data from the
> > controller to the model (as the current account, stored in
> > the session)? I''ve a "attr_writer ..." in the
model, but I
> > don''t know if it is the rails way :)
>
> Rails is single threaded, so there''s a really nice way to do this
>
> class Account < ActiveRecord::Base
> cattr_accessor :current_account
> end
>
> then in your before filter, just do this
>
> def before_filter
> Account.current_account= session[:account]
> end
>
> Now your model classes can access the current account like this:
>
> @account = Account.current_account
>
> It means you can encapsulate all your logic in your models and have
> the UI very very simple. It''s very much the ''rails
way'' even if I
> took the idea from my java work ;)
>
>
> > thanks
> >
> > --
> > Claudio Cicali
> > http://www.flexer.it
> > GPG Keyid: 1024D/555D25CE
> > ''Nos patriae finis et dulcia linquimus arva''
> > _______________________________________________
> > Rails mailing list
> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>
> --
> Cheers
>
> Koz
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>