Add `rails install` which installs the gem and runs install generator

Every time I want to add a new gem to a project, I have to open that gem’s documentation. That’s fine…for gems that I just discovered or never used before.

But for gems that I used in several other projects, I’d LOVE if I could just do rails install <gem_name> group:development and the rest is history.

I don’t remember by heart what’s the exact wording of ActiveAdmin generator or Devise generator, but I used those gems 100s of times and I know exactly what those install generators would do. Here are some different install generators I’ve found (note that most (but not all) are similar/the same). Convention over Configuration would really help unify this:

Gem name | Install generator

activeadmin | rails generate active_admin:install (underscore)

devise | rails generate devise:install (looks good!)

rolify | rails g rolify Role User (no :install, could use defaults or be interactive)

actiontext | rails action_text:install (no generate here, underscore)

delayed_job_active_record | rails generate delayed_job:active_record

cancancan | rails g cancan:ability

We can see that most of the gems gravitate around similar idea, but quite a big number of them do it their own way.

I think rails could replace this “Documentation over Configuration” with Convention over Configuration and introduce rails install command which will: add gem to Gemfile and run install generator if there is one that’s defined according to some rules (for example: <gem_name>:install)

It could also run migrations or that could be optional.


That sounds like a really interesting feature! It feels related to some of the work going on in Interactive “rails new” around a rails add feature and improving the Rails CLI experience overall. If you’d like to join forces with other folks, you can connect with them there!

1 Like

This is possibly similar to the work done in the Symfony community around Flex: Symfony Quick Tour: Flex: Compose your Application - we might choose to implement it differently, but they had some interesting ideas (and I can testify that it works pretty well for new applications).

Take a looks at Chris Oliver’s It’s fresh out of the oven and uses rails templates to achieve this.

1 Like

I took a quick look at Flex…the problem there as seems to happen a lot with “tool registries” in general…especially ones built up via PRs…is who manages the list? Who approves or verifies entries? How much time does it take to get added?

The key to Rubygems or NPM or whatever is it’s fully automated. No approval required. Should Rails also have a fully automated plugin registry? Can we build on top of Rubygems or GH APIs in some fashion? It’s a challenge for sure.

1 Like

My idea was to have “Convention over Configuration”. Rails would decide on the convention and, any gem that follows it, will get the feature automatically working.

For example: Convention could be: When running command rails install devise it:

  1. Adds gem to Gemfile and runs bundle install
  2. Checks if there’s exact generator called <gem_name>:install and runs it if there is
  3. Runs rails db:migrate or leaves this up to gem to do within the install generator

Notice that there’s no need for any kind of third-party solution. Gems are hosted wherever they are hosted: rubygems or private cloud, doesn’t matter. Gem will contain the logic for being installed with rails install.

PS RailsBytes looks amazing! :slight_smile: It’s solving this problem in an interesting way. I think at least basic install functionality can be part of rails core, while RailsBytes can still have any other template users want.


Ooo, I like that idea. Combines multiple existing steps into just one step. Big thumbs up from me!