Rails resources for surviving in the deep end?

Hi all,

I’m currently working in a large codebase that includes a Rails app.

Does anyone have some good resources that will help me dive in to the deep end of the code base - ideally something that gives good high level explanations of how the whole MVC thing works together, how to add routes etc…

I’m not really looking for a ‘starting from scratch, here’s how you make a blog’ kind of thing.

Ideally I’m imagining something that has good, annotated examples of semi-complex controller files, that explains in-line what before_action... does etc.

Any thing that helped Rails click for you will be appreciated though!

Thanks in advance :slight_smile:

The Rails docs are very good, keep them open to refer to. Just did a quick Google and these two articles cover what I’d normally do:

https://www.justinweiss.com/articles/finding-your-way-around-a-new-rails-project/

Basically, I would go on order:

  • look at db/schema.rb - this is a full overview of the database schema, used to build/rebuild the database structure of the app.
  • look at the Gemfile to see what dependencies the app is using, look at the readmes for the repos related to them and get familiar with a high level view of them
  • look at config/routes.rb. This is probably the most important file for understanding how the app works.
  • this can be backed up by running bin/rails routes on the command line, which will print every route in the app. Good reason for doing this: in the routes file, there’s a shorthand resources that can be used, which tells Rails to automatically generate index, single, create, edit, and delete routes for an endpoint; checking the routes in the CLI allows to actually see all of those.
  • Each endpoint will have a corresponding controller file, where the actions are defined - index(), single() etc.
  • Each of the methods in that controller will more than likely execute something on one or more models (get all from User, or get a single Product by ID)
  • Most of the methods in the controller will render a view if it has an HTML frontend (just JSON if it’s an API, which is easier), and views/ will have a series of subfolders, one for each controller
  • If you’re lucky, there will be tests - check those early on, if there is actual test coverage then that could be really helpful.

This is excellent, Dan, thanks!