I have a too many models and want to maitain separate validation and
relationship files for each model in rails. Is there any way i can maintain it
with rails?
Any specific advantage to do it?
I have a too many models and want to maitain separate validation and relationship
Share
Your question is not clear. By “models” you mean database-backed models that use ActiveRecord, right?
Usually validation is not a “file” but is a series of statements within the model’s file. Same for relationship declarations.
You can split a model’s contents amongst any number of files. The technique varies depending on whether you want the other files to contain instance methods or class methods.
Easiest is to have instance methods in other files. Eg
Offhand, I don’t how to put the callback override
in a different file than the model’s main class file. Wouldn’t be hard to figure out. But no matter how easy it would be to put in a different file, I would not recommend it from the code clarity point of view.