I have a too many models and want to maitain separate validation and relationship files for each model. Is there any way i can maintain it with rails? Any specific advantage to do it? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Juan José Vidal Agustín
2010-Jun-10 15:42 UTC
Re: Separate validation file for each model
You''d use a mixin. El 10/06/10 15:33, Krunal Shah escribió:> I have a too many models and want to maitain separate validation and > relationship files for each model. Is there any way i can maintain it > with rails? > Any specific advantage to do it? >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Krunal Shah wrote:> I have a too many models and want to maitain separate validation and > relationship files for each model.How will that change the fact that you have too many models?> Is there any way i can maintain it > with rails?Use mixins or subclasses.> Any specific advantage to do it?Explain more about your use case. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
# file foo.rb class Foo < ActiveRecord::Base include FooMethods # --- validations --- # # --- relationships --- # belongs_to :foobar has_many :bars # --- Class Methods --- # def Foo.a_method_name(id) ... end end ~~~~~~~~~~~~~~~~~~~~~~~~~~~ # file foo_methods.rb module FooMethods def method1 ... end def method2 ... end end If i will create a new module for every model to separate my validation and logic part. Than will it help anyway in load and other things? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Krunal Shah wrote:> # file foo.rb > class Foo < ActiveRecord::Base > include FooMethods > # --- validations --- # > # --- relationships --- # > belongs_to :foobar > has_many :bars > > # --- Class Methods --- # > def Foo.a_method_name(id) > ... > end > end > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > # file foo_methods.rb > > module FooMethods > > def method1 > ... > end > > def method2 > ... > end > > end > > > If i will create a new module for every model to separate my validation > and logic part. Than will it help anyway in load and other things?Don''t bother. It''s a completely pointless idea. Splitting your models into 2 files will provide no performance or architectural benefits that I can see, and will make your code harder to read. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.