originally posted at: https://github.com/rails/rails/issues/29647
Whenever I want to add a gem to my rails app, I go to specific gem’s github repo and follow the Readme instructions. Usually there are couple of steps to install the gem:
- Add the gem to your Gemfile
- This is almost always the same - possible config options could be:
require: false
orgroup :development, :test
- Run the gem’s generator
- Usually
rails generate gem_name:install
orrake gem_name:install:migrations
- Migrate the database
I have an idea that would streamline this process and make it easier to add gem to rails apps:
rails install
command
This command would install a ruby gem and run any necessary generators and setup code to make the gem fully installed and added to the app.
There are many times when I know the exact name of the gem but I can’t remember how | to | install | the | gem | correctly. Note that every one of these gems has different installation process, although all of these steps in all of these gems can be automatically executed (with sensible defaults that can be changed through cli arguments). Those gems that require more customization (for example: creating migration to add fields to existing models), could output that info right in the console after the installation (something similar to post-install gem message, but displayed every time after rails install
command, not only when installing gem for the first time.
Rails is all about Convention-over-Configuration. What we lack here is Convention.
Gem developers could add a simple config option (e.g. in .gemspec file) or dotfile to their gems that will set the flag that this gem follows (new) rails gem installation configuration. Then we could define the necessary instructions to fully install and setup the gem. It could work similarly to rails new
template.
Devise does something like this already for their install generator:
https://github.com/plataformatec/devise/blob/master/lib/generators/devise/install_generator.rb#L35
https://github.com/plataformatec/devise/tree/master/lib/generators/templates
This idea comes from ember install
:
https://github.com/ember-cli/ember-cli#install-an-ember-cli-addon