Hi all, A newbie with Ruby on Rails - and programming in general - I''m working on a few Flash and PHP projects as well. Partly to make my work more efficient, partly to gain a better understanding of system architecture / design patterns, I''ve been trying to use the MVC pattern in database-backed Flash / Actionscript development as well. I think / hope that I''m beginning to grasp the concept of patterns - and of the MVC one. One question however; if starting out designing a new MVC application, how do I identify the Model classes - will it always be one model per DB table? And is there a general ''model'' for identifying controllers - when you start out from scratch developing a new app? Any feedback much appreciated, BR Bo / Rails newbie -- Posted via http://www.ruby-forum.com/.
On 11 Aug 2006, at 16:47, Bo Vittrup wrote:> A newbie with Ruby on Rails - and programming in general - I''m working > on a few Flash and PHP projects as well. Partly to make my work more > efficient, partly to gain a better understanding of system > architecture > / design patterns, I''ve been trying to use the MVC pattern in > database-backed Flash / Actionscript development as well. > > I think / hope that I''m beginning to grasp the concept of patterns > - and > of the MVC one.Skipping carefully over the idea that MVC might be a lowly pattern...> One question however; if starting out designing a new MVC application, > how do I identify the Model classes - will it always be one model > per DB > table?If you are starting out, a model class will usually be one per table, yes. But be aware that you are likely to be able to identify models that don''t map to any table at all, and may have designs that require more than one model class per table. And some tables (join tables, mostly) won''t require classes.> And is there a general ''model'' for identifying controllers - when > you start out from scratch developing a new app?Controllers can be viewed as convenient groupings of actions, possibly optimised by how they share supporting methods and helpers. I like the idea that actions in one controller share a layout - so the number of controllers in your app is the same as the number of layouts. That is all very crude, and is really a matter of taste more than anything else. Paul
I''m also new to this stuff, but as far as I''ve seen, you have one model class for each table in the DB. More especifically, you have one ActiveRecord::Base class for each table. If you have another model but is not related to any table (dunno, a transient class), you will have another file in your app/model, but just defined as "class TransientStuff end", not ActiveRecord. (I don''t understand the question about the "general model" :)). Bo Vittrup wrote:> Hi all, > > A newbie with Ruby on Rails - and programming in general - I''m working > on a few Flash and PHP projects as well. Partly to make my work more > efficient, partly to gain a better understanding of system architecture > / design patterns, I''ve been trying to use the MVC pattern in > database-backed Flash / Actionscript development as well. > > I think / hope that I''m beginning to grasp the concept of patterns - and > of the MVC one. > > One question however; if starting out designing a new MVC application, > how do I identify the Model classes - will it always be one model per DB > table? And is there a general ''model'' for identifying controllers - when > you start out from scratch developing a new app? > > Any feedback much appreciated, > BR Bo / Rails newbie-- Posted via http://www.ruby-forum.com/.
Thank you both for your comments. I think that I understand better now that there is no ''one way'' of structuring an application using a particular pattern model, and that in the end a lot depends on personal preferences and tastes. However, your answers together with various tutorials using different programming languages (Java, Actionscript etc.) forms a good starting point - and from there the only way is probably to try it out a thousand times for oneself and adjust and get smarter along the way : ) And - anyway, as long as you stick to Rails, it is great that a lot of the thinking has already been done and that you''re able to build on lots of experience gained by others. Br Bo Paul Lynch wrote:> On 11 Aug 2006, at 16:47, Bo Vittrup wrote: > >> A newbie with Ruby on Rails - and programming in general - I''m working >> on a few Flash and PHP projects as well. Partly to make my work more >> efficient, partly to gain a better understanding of system >> architecture >> / design patterns, I''ve been trying to use the MVC pattern in >> database-backed Flash / Actionscript development as well. >> >> I think / hope that I''m beginning to grasp the concept of patterns >> - and >> of the MVC one. > > Skipping carefully over the idea that MVC might be a lowly pattern... > >> One question however; if starting out designing a new MVC application, >> how do I identify the Model classes - will it always be one model >> per DB >> table? > > If you are starting out, a model class will usually be one per table, > yes. But be aware that you are likely to be able to identify models > that don''t map to any table at all, and may have designs that require > more than one model class per table. And some tables (join tables, > mostly) won''t require classes. > >> And is there a general ''model'' for identifying controllers - when >> you start out from scratch developing a new app? > > Controllers can be viewed as convenient groupings of actions, > possibly optimised by how they share supporting methods and helpers. > I like the idea that actions in one controller share a layout - so > the number of controllers in your app is the same as the number of > layouts. That is all very crude, and is really a matter of taste > more than anything else. > > Paul-- Posted via http://www.ruby-forum.com/.