Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you read an existing Rails project?

When you start working on an existing Rails project what are the steps that you take to understand the code? Where do you start? What do you use to get a high level view before drilling down into the controllers, models, helpers and views? Do you have any specific techniques, tricks or tools that help speed up the process?

Please don't respond with "Learn Rails & Ruby" (like one of the responses the last guy who asked this got - he also didn't get much response to his question so I thought I would ask again and prompt a bit more). I'm pretty comfortable with my own code. It's sorting other people's that does my head in and takes me a long time to grok.

like image 712
srboisvert Avatar asked Jan 31 '09 13:01

srboisvert


2 Answers

Look at the models. If the app was written well, this should give you a picture of its domain model, which is where the interesting logic should live. I also look at the tests for the models.

The way that the controllers/views were implemented should be apparent just by using the Rails app and observing the URLs.

Unfortunately, there are many occasions where too much logic lives in controllers and even views. That means you'll have to take a look into those directories too. Doubley-unfortunate, tests for these layers tend to be much less clear.

like image 180
nakajima Avatar answered Oct 20 '22 01:10

nakajima


First I use the app, noting the interesting controller and action names.

Then I start reading the code for these controllers, and for the relevant models when necessary. Views are usually less important.

like image 20
Can Berk Güder Avatar answered Oct 19 '22 23:10

Can Berk Güder