Your Rails app basically writing itself, thanks to your brilliant knowledge of all the available Rails generators
PgAnalyze helps you deliver consistent database performance through intelligent tuning advisors and continuous database profiling.
Welcome to The RailsNotes Newsletter — Issue #18! This issue is all about Rails Generators!
I would argue that being able to effectively use the built-in Rails generators is one of the most valuable skills for a Rails engineer! Being able to generate a full migration in a single command, 10+ files for a RESTful resource, or quickly spin up a new
rake task are all extremely valuable skills, and Rails generators let you do that!
The featured ✨new Rails tool of mine ✨ should help you learn about Rails generators; The rest of the articles in this newsletter go a bit deeper and cover things like overriding the default behaviour of your Rails generators and creating new ones.
Thanks as well to our now-quite-regular sponsor PgAnalyze — they continue to support me and the newsletter, so thank you! It helps us both if you check them out, browse their product etc. If you’ve got any questions, feel free to reach out and I can try to answer, or put you in touch with someone from PgAnalyze.
With all that said, let’s dive into this week’s newsletter!
~ ✨ FEATURED ARTICLE ✨ ~
I’m launching a cool new free tool! railsg.xyz is a handy GUI tool for writing Rails generator commands!
Are you familiar with the Rails
scaffold_controller generator? You are! Well, how about the
benchmark generator? And do you know what flags you can pass the
If you answered “no” to any of those questions, I think I built something that you’ll find handy! I’ve been building 🔨 a Rails Generator Command Builder, to let you browse through all the different Rails generators that exist, and explore all the different flags and options you can pass.
As part of this, I’ve built a GUI command builder; Here’s a GIF showing you how it works 👇️
Check it out and have a play around! If you’ve got a second, I’d also love your thoughts and feedback (just reply to this email, and I’ll get your response!). Right now I’ve got all the main Rails generators (plus the Stimulus Controller generator).
If you’re not sure where to start, I recommend rails generate scaffold_controller — this is a generator I use all the time, but I went years without even knowing it existed! (It lets you create the matching controller and views for an existing model)
Hope you find this useful!
~ MORE ARTICLES ~
This is a great article by Chris which takes a deeper look at Rails generators and some more advanced concepts.
Chris covers tweaking
config/application.rb to override behaviour you don’t want (ie: maybe you want to skip generating helper files), and overriding your existing generators to add extra functionality (like including Devise actions in your controllers). Well worth a read!
This article takes a much deeper look at modifying an existing Rails generator. Specifically, this article walks you through overriding the
task generator, and teaches you a lot along the way!
I was struggling to find another generator-related article that I liked enough to include. Rather than including a meh-to-crappy article, I decided to just leave this section blank….
…well…. not quite blank. I guess I should put something into this section (beyond my latent musings), so here’s a sick picture that I just got DALLE-3 to generate for me, but wasn’t going to use for this newsletter 👇️
Prompt: A cute isometric robotic factory layout, showing the production line of a cute red robot. the picture is intricate and zoomed out. The operators of the factory are little anthropomorphic red diamond characters. Give the factory multiple levels, and include lots of nuance and interactions between the characters. Heavy dark lines, warm lighting, vibrant comic style
~ ⚒️ HANDY TIP ~
→ View a list of all your available generators with
Rails has a lot of generators! To get a full list of them, you can run
rails g from inside an existing Rails app — you’ll get a list of every single generator you’ve got available.
Bonus: If you’re inside a bash shell (basically any MacOS or Linux PC), you can combine this with a pipe to grep,
rails g | grep [name] to search for a specific generator!
rails g | grep rspec
❯ rails g