When you’re starting out, one of the best ways to learn is by looking at code written by more experienced developers; especially when it comes to learning key concepts like “the Rails Way”.
But where do you begin?
It can be a struggle to figure out how a particular app works when you have loads of models and controllers to wade through.
Well, as you might expect, if the app has tests, then they are a great place to start. Especially if the acceptance tests are written in Cucumber or Spinach. You have a definition, written in English, of what the code is supposed to do. You can go through a feature at a time and trace through the code, from test to route to controller to model and back through to the view. If the tests are written in Ruby (either as RSpec or MiniTest) then you’ve got a bit of parsing to do, but you should still be able to get a good idea of how things hang together.
If you dont have tests then an excellent place to start is the schema.rb file. This is a Ruby description of the database structure and from it you should be able to see which models are important and how they relate to each other. You should also be able to get an insight into how cleanly the developer has modelled the application.
Lastly, the routes file is a great place to understand things from the user’s point of view. Hopefully it should use predominantly Restful routing (if it does not then you will have a load of stuff, probably not very well-organised, to sift through by hand). Restful routes will give you an idea of the concepts that are important to the user (as they will be reflected in the URLs) and the nesting will give you some insight into the application structure.
So there you have it; three places to look to get an insight into someone else’s application, tests, schema and routes.