Danny Yavorski
2007-Oct-17 08:34 UTC
Does the model and the controller share a 1to1 relatioship?
Hi all I am a very experienced programmer (and therefor can appriciate the rails framework as the right thing) But a totally new to Rails. I am trying to build a website that includes a front-end for users and an admin system(CMS) for the web administrator. I have around 12 different tables that supposed to be managed by the web administrator. For each one of them, I created a model. Now, I am looking to create the CMS and I would have been more then happy to do the following: 1)Create an "admin" controller 2)"Scaffold" all the models under that controller e.g. AdminController < ApplicationController Scaffold table1 Scaffold table2 Scaffold table3 etc. Well... I can''t This lead brought me to the big question: Does the model and the controller share a one to one relationship? Thanks a lot Danny -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Peter
2007-Oct-17 13:36 UTC
Re: Does the model and the controller share a 1to1 relatioship?
Hi Danny, As far as I know if you''re using scaffolding then yes, its 1 controller per model. However if you are writing the controller code yourself there is no such limit, you can ''access'' as many models as you want from as many (or as few) controllers as you want. Generally speaking I try to keep related stuff in the same controller, rather than sticking to 1:1 HTH Peter On Oct 17, 9:34 am, Danny Yavorski <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi all > I am a very experienced programmer (and therefor can appriciate the > rails framework as the right thing) But a totally new to Rails. > I am trying to build a website that includes a front-end for users and > an admin system(CMS) for the web administrator. > > I have around 12 different tables that supposed to be managed by the web > administrator. For each one of them, I created a model. > > Now, I am looking to create the CMS and I would have been more then > happy to do the following: > > 1)Create an "admin" controller > 2)"Scaffold" all the models under that controller > > e.g. > > AdminController < ApplicationController > Scaffold table1 > Scaffold table2 > Scaffold table3 > etc. > > Well... I can''t > > This lead brought me to the big question: > Does the model and the controller share a one to one relationship? > Thanks a lot > Danny > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
randomutterings...
2007-Oct-17 13:38 UTC
Re: Does the model and the controller share a 1to1 relatioship?
The controller and model do not share a 1 to 1 relationship although in many apps that is what you end up with. It keeps the app simple and easy to understand when you go back to it later. The think I love about rails is that most of the time when I''m debugging, I read the error and immediately know what the problem is. Recently, I took a look at a rails CMS/Shopping cart called Substruct. It works well but when I tried to customize it, I found I spent most of my time digging through controllers and models trying to figure out how it worked so I could change it for my needs. I could not find a pattern of mapping models to controllers at all and after a while, it reminded me of debugging php apps. Some apps I''ve written contain controllers that are not mapped 1 to 1 with models and that is fine because in that instance there was a good reason for it but even in those apps, most of the models/controllers are 1 to 1. For me, the organization of controllers and models is about keeping the code clean and easy to understand and come back to later. On Oct 17, 4:34 am, Danny Yavorski <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi all > I am a very experienced programmer (and therefor can appriciate the > rails framework as the right thing) But a totally new to Rails. > I am trying to build a website that includes a front-end for users and > an admin system(CMS) for the web administrator. > > I have around 12 different tables that supposed to be managed by the web > administrator. For each one of them, I created a model. > > Now, I am looking to create the CMS and I would have been more then > happy to do the following: > > 1)Create an "admin" controller > 2)"Scaffold" all the models under that controller > > e.g. > > AdminController < ApplicationController > Scaffold table1 > Scaffold table2 > Scaffold table3 > etc. > > Well... I can''t > > This lead brought me to the big question: > Does the model and the controller share a one to one relationship? > Thanks a lot > Danny > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-Oct-17 14:51 UTC
Re: Does the model and the controller share a 1to1 relatioship?
On 10/17/07, Danny Yavorski <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Now, I am looking to create the CMS and I would have been more then > happy to do the following: > > 1)Create an "admin" controller > 2)"Scaffold" all the models under that controller > > e.g. > > AdminController < ApplicationController > Scaffold table1 > Scaffold table2 > Scaffold table3 > etc. > > Well... I can''t > > This lead brought me to the big question: > Does the model and the controller share a one to one relationship?No, there is no forced relationship between controllers and models. The issue with multiple scaffolds in the controller is that you get duplicate action names generated. But you can do it with a :suffix option. From the API docs for the scaffold method: "It''s possible to use more than one scaffold in a single controller by specifying options[:suffix] = true. This will make scaffold :post, :suffix => true use method names like list_post, show_post, and create_post instead of just list, show, and post. If suffix is used, then no index method is added." --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---