I don''t understand the concept behind how Rails models should be structured. When i run "rails <app-name>" a single model file (app/models/<app-name>.rb) is generated. But, typically, i have a number of tables in my database. I have ended up just sticking the class definitions for most of my tables into this single model file... which feels inconsistent to me on some level. On the other hand, i see no benefit (to say the least) in creating a separate file for each table/class definition. Therefore, according to my understanding, i would have designed rails to create a single model file... which Rails does. But with what intention? Since it creates a model file <app-name>.rb but automatically creates within it the definition for a *single* class which assumes that there is an <app-name> *table* within your database, i was thinking of this file as <table-name>.rb rather than <app-name>.rb (even though <table-name> and <app-name> are the same). So, i found that confusing. Further, what is the idea of assuming that you must have an <app-name> table in your database? And creating a *single* class definition for just one of the tables in your database? This really makes no logical sense to me. What is the purpose of defining this *single* model class? Is it just as an example of what you need to do for other (relevant) tables as well? But what is the implication as to *where* you should define your other classes (given that the file that the predefined class is in is named the same as one of your db tables?) I don''t perceive an overarching logic to this aspect of the AR design is what i''m trying to say. But maybe i''m missing something. craig "Minimal sufficient logic is the best indicator for figuring out the intention of code. Absent this you''re just left guessing."
craig duncan <craig-duncan-ihVZJaRskl1bRRN4PJnoQQ@public.gmane.org> writes:> When i run "rails <app-name>" a single model file > (app/models/<app-name>.rb) is generated. But, typically, i have a > number of tables in my database. I have ended up just sticking the > class definitions for most of my tables into this single model fileRails pretty much assumes every table will have it''s own app/model/<table-name>.rb file. The <app-name>.rb file doesn''t correspond to a table, but to global model changes for the whole app. You should use the generator to build models for each table you have. In learning Rails, I''ve found it''s better to think about your business objects rather than just tables. There''s not always a 1:1 mapping of model objects to database tables. For instance join tables don''t get their own object but are represented as a relationship between two models. Also in using Single Table Inheritance, you have one table and multiple model objects stored in it. I don''t know how many of the tutorials you''ve worked through. I really suggest working through as many of them as you can before diving right in and starting coding. Rails is a slightly different frame of mind than other frameworks I had exposure to. Working through the tutorials helped me get a feel for the "Rails Way" of doing things. Incidentally, I''ll chime in with my $0.02 on the whole "10x more productive" deal. I really like the way Rails structures things. The end result is a clean, well tested application. However, for the hoards of us average programmers it''s less than trivial for us to pick up Rails and start churning out complete web applications in an afternoon. These guys who post to the mailing list and say, "Hi! I''m new to rails. Here''s my first web application I put together for my client this weekend," really aggravate me. I''ve been working fairly consistently over a number of weeks in the evenings and don''t have a working app yet. John Wilgar (who can certainly speak for himself) told the xp-cinci group his eXPlain project tracker took him about 60 hours of work. That''s a number I can be comfortable with. John''s at least moderately Ruby/Rails experienced. I guess all I''m saying is that if you start learning Rails on Rails Day you probably won''t have a functioning, original app by the end of the day. Also, depending on how much experience you have with real Object Oriented Design (as opposed to simply working in a language that supports objects) and MCV, it may take you longer to come up to speed with Rails. Good luck and keep us posted! -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org
craig duncan <craig-duncan-ihVZJaRskl1bRRN4PJnoQQ@public.gmane.org> writes:> When i run "rails <app-name>" a single model file > (app/models/<app-name>.rb) is generated. But, typically, i have a > number of tables in my database. I have ended up just sticking the > class definitions for most of my tables into this single model file.Rails pretty much assumes every table will have it''s own app/model/<table-name>.rb file. The <app-name>.rb file doesn''t correspond to a table, but to global model changes for the whole app. You should use the generator to build models for each table you have. In learning Rails, I''ve found it''s better to think about your business objects rather than just tables. There''s not always a 1:1 mapping of model objects to database tables. For instance join tables don''t get their own object but are represented as a relationship between two models. Also in using Single Table Inheritance, you have one table and multiple model objects stored in it. I don''t know how many of the tutorials you''ve worked through. I really suggest working through as many of them as you can before diving right in and starting coding. Rails is a slightly different frame of mind than other frameworks I had exposure to. Working through the tutorials helped me get a feel for the "Rails Way" of doing things. Incidentally, I''ll chime in with my $0.02 on the whole "10x more productive" deal. I really like the way Rails structures things. The end result is a clean, well tested application. However, for the hoards of us average programmers it''s less than trivial for us to pick up Rails and start churning out complete web applications in an afternoon. These guys who post to the mailing list and say, "Hi! I''m new to rails. Here''s my first web application I put together for my client this weekend," really aggravate me. I''ve been working fairly consistently over a number of weeks in the evenings and don''t have a working app yet. John Wilgar (who can certainly speak for himself) told the xp-cinci group his eXPlain project tracker took him about 60 hours of work. That''s a number I can be comfortable with. John''s at least moderately Ruby/Rails experienced. I guess all I''m saying is that if you start learning Rails on Rails Day you probably won''t have a functioning, original app by the end of the day. Also, depending on how much experience you have with real Object Oriented Design (as opposed to simply working in a language that supports objects) and MCV, it may take you longer to come up to speed with Rails. Good luck and keep us posted! -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org