I have a tag cloud that is made up of Tags(model with table). I want the tag cloud to be a model but I do not need a table since I am going to get the data from Tag. I was wondering how do I create a model that does not depend on a table? Is this a bad practice? Does anyone see me doing it another way? Thanks :-) -- John Kopanas john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
x1.sean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-09 17:55 UTC
Re: Model Without Associated Table
Not every model (or ruby class ) needs to relate to a table in the database. Actually a given class only gets that functionality when it inherits from ActiveRecord::Base. class TagCloud ... end would work without any related table... hope that helps. -Sean --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Who would of thought. For some odd reason I was under the impression that if I took out ActiveRecord::Base then the framework would burn into the ground... but it still works :-). On 9/9/06, x1.sean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <x1.sean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Not every model (or ruby class ) needs to relate to a table in the > database. Actually a given class only gets that functionality when it > inherits from ActiveRecord::Base. > > class TagCloud > ... > end > > would work without any related table... > > hope that helps. > > -Sean > > > > >-- John Kopanas john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Sep 8, 2006, at 8:53 PM, John Kopanas wrote:> > I have a tag cloud that is made up of Tags(model with table). I want > the tag cloud to be a model but I do not need a table since I am going > to get the data from Tag. I was wondering how do I create a model > that does not depend on a table? Is this a bad practice? Does anyone > see me doing it another way? Thanks :-) > > -- > John Kopanas > john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.orgIn this case you may want to just make a plain old ruby class that doesn''t inherit from AR::Base, put it in your models dir and let it do whatever it wants to with the Tag model. class TagCloud def self.[](num) Tag.find(:all, :limit => num) # or whatever, you get the idea. end end You would use this to output a cloud of 25 tags like so: TagCloud[25] Or you can use some form of delegation to the Tag model. I use plain ruby models like this as sort of coordination-models that coordinate multiple ActiveRecord models but don''t need to keep their own state in the database. So these are good places for complex logic that deals with multiple AR models at once. -Ezra --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---