hi all I have two different models representing two different data sets but I want to use the same controler and views to process them how can I DRY this up so I don''t have to use a separate controller and view for each model? would helpers be the solution? so their urls''s would work like this: www.site.com/model1/draws/view/1 www.site.com/model2/draws/view/1 cheers dion --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 4, 12:30 am, "Dion Hewson" <dionhew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi all > > I have two different models representing two different data sets > > but I want to use the same controler and views to process them > > how can I DRY this up so I don''t have to use a separate controller and view > for each model?Wasn''t it easier to DRY up your models instead of controllers and views? If those data sets use logic that is close enough to require identical views, chances are you could merge those models with an extra column or two for identifying the kind. Just a wild guess, of course, since you gave us only so much details. Otherwise, I think with the URLs you have posted, you may not need helpers. Use the model1/model2 part as an extra parameter, and process that in the controller to get the right records. (Sorry if I''m not making any sense). Kind regards, Branko --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Branko... you made perfect sense...I have thought about those two options as well, using the same model would be easy, but I thought it might be cleaner to have two different models, for the two slightly different datasets...(normalisation) but testing for the model name as a parameter in the route would be should be just as easy... however out of the three options...i''m not sure which one is the ''rails'' way to do it... On Tue, Mar 4, 2008 at 10:19 AM, foxbunny <bg.branko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Mar 4, 12:30 am, "Dion Hewson" <dionhew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > hi all > > > > I have two different models representing two different data sets > > > > but I want to use the same controler and views to process them > > > > how can I DRY this up so I don''t have to use a separate controller and > view > > for each model? > > Wasn''t it easier to DRY up your models instead of controllers and > views? > > If those data sets use logic that is close enough to require identical > views, chances are you could merge those models with an extra column > or two for identifying the kind. Just a wild guess, of course, since > you gave us only so much details. > > Otherwise, I think with the URLs you have posted, you may not need > helpers. Use the model1/model2 part as an extra parameter, and process > that in the controller to get the right records. (Sorry if I''m not > making any sense). > > Kind regards, > > Branko > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 4, 1:09 am, "Dion Hewson" <dionhew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> however out of the three options...i''m not sure which one is the ''rails'' way > to do it...Well, I''m quite new to Rails so I wouldn''t know what exactly would be the true Rails way. But I guess the less you fight Rails, the closer your are to Rails way. ;-) Branko --~--~---------~--~----~------------~-------~--~----~ 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 don''t know if it could help in your case but you could do single- table inheritance : (see http://api.rubyonrails.com/classes/ActiveRecord/Base.html ) to put things simply, you add a column named "type" (with datatype set to string) in the table that will contain both models then, in the general model file: class GeneralModel < ActiveRecord::Base # code goes here end class SpecializedModel1 < GeneralModel end class SpecializedModel2 < GeneralModel end then if each specialized model has some really unique properties, you can wrap these in a column that you would then serialize into a specific object type, which could be a Hash or anything else (serialization is also covered in the article I provided the link for). If this doesn''t help in any way, check out : http://api.rubyonrails.com/classes/ActionController/Resources.html it contains documentation for "resource", and "resources" methods, which accept the "controller" and "path_prefix" parameters you could find use for. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---