Hi- I have a single controller that''s associated with a single model. I would now like to create a whole bunch more models to use the same controller, is this a bad idea? If I use the scaffold generator (which takes the controller and model as inputs) will this wipe out all the work I have already done for the first model (in the views and controller)? What is the best way to go when you have a lot of models and a single controller? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I''m guessing you want to perform some operation on multiple models in the same action. You can use: script/generate model ModelName name:string this:integer that:boolean This lets you generate all the extra models (and migrations). You''ll then need to add them into the controller yourself. On Jan 23, 9:40 am, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi- > > I have a single controller that''s associated with a single model. I > would now like to create a whole bunch more models to use the same > controller, is this a bad idea? > > If I use the scaffold generator (which takes the controller and model > as inputs) will this wipe out all the work I have already done for the > first model (in the views and controller)? > > What is the best way to go when you have a lot of models and a single > controller? > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes, I will essentially do the same things with the new model. What are the extra parameters doing in the generator? On Jan 23, 3:44 pm, danlunde <danlu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m guessing you want to perform some operation on multiple models in > the same action. > > You can use: script/generate model ModelName name:string this:integer > that:boolean > > This lets you generate all the extra models (and migrations). You''ll > then need to add them into the controller yourself. > > On Jan 23, 9:40 am, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi- > > > I have a single controller that''s associated with a single model. I > > would now like to create a whole bunch more models to use the same > > controller, is this a bad idea? > > > If I use the scaffold generator (which takes the controller and model > > as inputs) will this wipe out all the work I have already done for the > > first model (in the views and controller)? > > > What is the best way to go when you have a lot of models and a single > > controller? > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nevermind...I looked it up, sorry for being lazy :) So, a question on good practice: Having multiple models in one controller is a good/normal thing? On Jan 23, 3:54 pm, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes, I will essentially do the same things with the new model. > > What are the extra parameters doing in the generator? > > On Jan 23, 3:44 pm, danlunde <danlu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''m guessing you want to perform some operation on multiple models in > > the same action. > > > You can use: script/generate model ModelName name:string this:integer > > that:boolean > > > This lets you generate all the extra models (and migrations). You''ll > > then need to add them into the controller yourself. > > > On Jan 23, 9:40 am, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi- > > > > I have a single controller that''s associated with a single model. I > > > would now like to create a whole bunch more models to use the same > > > controller, is this a bad idea? > > > > If I use the scaffold generator (which takes the controller and model > > > as inputs) will this wipe out all the work I have already done for the > > > first model (in the views and controller)? > > > > What is the best way to go when you have a lot of models and a single > > > controller? > > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The extra (optional) arguments after the ModelName will prepopulate the generated migration file with the columns (and types) specified. On Jan 23, 10:54 am, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes, I will essentially do the same things with the new model. > > What are the extra parameters doing in the generator? > > On Jan 23, 3:44 pm, danlunde <danlu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''m guessing you want to perform some operation on multiple models in > > the same action. > > > You can use: script/generate model ModelName name:string this:integer > > that:boolean > > > This lets you generate all the extra models (and migrations). You''ll > > then need to add them into the controller yourself. > > > On Jan 23, 9:40 am, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi- > > > > I have a single controller that''s associated with a single model. I > > > would now like to create a whole bunch more models to use the same > > > controller, is this a bad idea? > > > > If I use the scaffold generator (which takes the controller and model > > > as inputs) will this wipe out all the work I have already done for the > > > first model (in the views and controller)? > > > > What is the best way to go when you have a lot of models and a single > > > controller? > > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
There''s nothing inherently wrong with multiple models in a controller. Often times, though, you''re dealing with a single model and its associations (which are other models). For instance, finding a product and its category, brand, sizes, and colors. You only need: @product = Product.find(params[:id]) to get @product.brand, @product.category, @product.sizes, etc. There''s a really good screencast on doing CRUD with associations here: http://railscasts.com/episodes/73 On Jan 23, 11:24 am, Daniel Lunde <danlu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The extra (optional) arguments after the ModelName will prepopulate > the generated migration file with the columns (and types) specified. > > On Jan 23, 10:54 am, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Yes, I will essentially do the same things with the new model. > > > What are the extra parameters doing in the generator? > > > On Jan 23, 3:44 pm, danlunde <danlu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''m guessing you want to perform some operation on multiple models in > > > the same action. > > > > You can use: script/generate model ModelName name:string this:integer > > > that:boolean > > > > This lets you generate all the extra models (and migrations). You''ll > > > then need to add them into the controller yourself. > > > > On Jan 23, 9:40 am, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi- > > > > > I have a single controller that''s associated with a single model. I > > > > would now like to create a whole bunch more models to use the same > > > > controller, is this a bad idea? > > > > > If I use the scaffold generator (which takes the controller and model > > > > as inputs) will this wipe out all the work I have already done for the > > > > first model (in the views and controller)? > > > > > What is the best way to go when you have a lot of models and a single > > > > controller? > > > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ok. Thanks very much for your feedback! On Jan 23, 4:37 pm, Daniel Lunde <danlu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> There''s nothing inherently wrong with multiple models in a > controller. Often times, though, you''re dealing with a single model > and its associations (which are other models). For instance, finding > a product and its category, brand, sizes, and colors. You only need: > @product = Product.find(params[:id]) to get @product.brand, > @product.category, @product.sizes, etc. > > There''s a really good screencast on doing CRUD with associations here:http://railscasts.com/episodes/73 > > On Jan 23, 11:24 am, Daniel Lunde <danlu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > The extra (optional) arguments after the ModelName will prepopulate > > the generated migration file with the columns (and types) specified. > > > On Jan 23, 10:54 am, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Yes, I will essentially do the same things with the new model. > > > > What are the extra parameters doing in the generator? > > > > On Jan 23, 3:44 pm, danlunde <danlu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m guessing you want to perform some operation on multiple models in > > > > the same action. > > > > > You can use: script/generate model ModelName name:string this:integer > > > > that:boolean > > > > > This lets you generate all the extra models (and migrations). You''ll > > > > then need to add them into the controller yourself. > > > > > On Jan 23, 9:40 am, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi- > > > > > > I have a single controller that''s associated with a single model. I > > > > > would now like to create a whole bunch more models to use the same > > > > > controller, is this a bad idea? > > > > > > If I use the scaffold generator (which takes the controller and model > > > > > as inputs) will this wipe out all the work I have already done for the > > > > > first model (in the views and controller)? > > > > > > What is the best way to go when you have a lot of models and a single > > > > > controller? > > > > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I find it better, even though multiple controllers do very much the same thing, to have a separate controller for every model in the case that if I have to change something in one model I don''t have to split it up later on. It''s also more along the lines of the Rails way. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---