krunal shah
krunal shah

Reputation: 16339

Need suggestion for Ruby and Rails coding standards

I am developing my application using Rails. It has 400 or more models and some models contain more than 200 rows just for relationships, so it's too hard handle it. Are there any ways I can handle my application in more proper and easy ways?

Upvotes: 2

Views: 344

Answers (1)

samuil
samuil

Reputation: 5081

In application that I'm working with, there are about 100 models. Few things that helped us develop it:

  • you can create hierarchical directory structure to models. It is obvious when talking about controllers, but for models it's not that straightforward
  • you can split models into logical parts by putting chunks of code into modules
  • doing above two points sometimes allows you to see some ways to refactor your code. Some modules might become common between models. Some things can be excluded into methods that will dynamically generate common parts of models
  • sometimes modules handle unnecessary logic, and that makes harder to understand them -- if your methods contain lots of cases or ifs to handle different types of objects (like admin/normal user) probably you should use polymorphism
  • refactor, refactor, refactor ;-)

Wise refactoring takes a lot of time, but if you drop this part of development, project maintenance will become overwhelming. Check out books about Ruby, RoR, refactoring, metaprogramming. Investing time in learning might also bring effects.

Upvotes: 2

Related Questions