Hacker News new | ask | show | jobs
by rubiquity 4130 days ago
Realistically, you only need to memorize a few:

- rake test: run the entire test suite

- rails s: run the rails server

- rails c: opens up an IRB/pry session with your Rails app

- rails g migration: create a new migration

- rake db:migrate - Run new migrations

- rake db:create - create the DB the first time

- rake db:schema:load - generate the DB from schema.rb

- rake db:setup - generate a new database from migrations

- rake routes - Spit out the routes and path helpers

Don't ever use rails generate model/controller. It generates so much garbage that you likely won't need.

There are a bunch of other commands off of rake db:migrate but most aren't needing to be memorized. Our brains are only so large and dense and mine is particularly small, memorize what is important and memorize how to look up the rest.

4 comments

'rake' also runs the entire test suite, as it's an alias for 'rake test'.

I really disagree on the bit about not using rails g for controllers, and especially models. If you include your fields and types in the generate command you are given the corresponding migration, fixture, and test file for said model. If most of what you need can be generated by a single command, that's a whole lot less to remember compared to the intricacies of manually creating migrations, fixtures, test files etc. The generate commands have gotten so solid throughout the years, you can even do polymorphic and other associations through them and skip manually writing out all those details at this point. A whole lot less to remember there.

I think I made the decision a couple years ago that I'd rather just remember what the files should look like and create them as I need them. I work on varying types of Rails apps (some full-on HTML/JS and others just JSON APIs) where a lot of times you don't need most of those files. I could see merit in just remembering the generator commands, though.
I see. I'm on the same boat as far as developing varying types of apps w/ Rails. Disabling things I don't need, like asset pipeline for API dev is pretty quick: config.assets.enabled and config.generators.assets set to false and you don't have to worry about generators creating any unnecessary js/css in that scenario. Out of curiosity, what other things are being generated that wouldn't be of use?
Resource-based SCSS/CoffeeScript files. For an API I definitely don't need these, for a regular app I don't need them because I try to write JS/CSS around components rather than resources.

Good call on just removing the generators though. I should just do that.

With the rake tasks, you're better off learning "rake -T" (list all rake tasks that have a description). You can find the one you need in there, and the most common ones will soon sink in via osmosis as you use them regularly.
I use "rails g [x]" a lot, for models and controllers, and less frequently scaffold.

I don't see the penalty for some empty javascript files etc. And I like having everything where it belongs.

The only ones I know from memory is:

script/rails console and rake db:migrate

everything else I look up online, and I've been coding for 5 years in rails