Separate validation file for each model

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'd use a mixin.

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,

# 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

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,