Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for How to create tons of Rails applications
David Boureau
David Boureau

Posted on • Edited on • Originally published atalsohelp.com

     

How to create tons of Rails applications

Article originally published here :https://alsohelp.com/blog/how-to-create-tons-rails-applications

1. Motivation

AtBootrAils, we are using this script every (working !) day. It allows you to :

  • grab any concept,
  • isolate a bug quickly,
  • play with new Rails features,

... without any side effect.

Side note for beginners : It's also an excellent way to improve your Ruby-on-Rails skills. The more you create new apps from scratch, the more you understand the directory structure, the philosophy, and the internals of Rails.

2. The trick

Open~.bash_profile on your linux-based computer.

We will create a bash function, namedcnra (an acronym that means "create new rails application"). Acronyms are very handy to avoid remembering every shortcut.

# inside ~.bash_profile## Usage :# $> cnra myapp 7.0.0 --minimal --database=postgresql#cnra(){# create dir, dive into dir, require desired Rails versionmkdir-p--"$1"&&cd-P--"$1"echo"source 'https://rubygems.org'"> Gemfileecho"gem 'rails', '$2'">> Gemfile# install rails, create new rails app  bundleinstallbundleexecrails new.--force${@:3:99}  bundle update# Create a default controllerecho"class HomeController < ApplicationController"> app/controllers/home_controller.rbecho"end">> app/controllers/home_controller.rb# Create a default routeecho"Rails.application.routes.draw do"> config/routes.rbecho'  get "home/index"'>> config/routes.rbecho'  root to: "home#index"'>> config/routes.rbecho'end'>> config/routes.rb# Create a default viewmkdirapp/views/homeecho'<h1>This is h1 title</h1>'> app/views/home/index.html.erb# Create database and schema.rb  bin/rails db:create  bin/rails db:migrate}
Enter fullscreen modeExit fullscreen mode

Note the trick${@:3:99} that means "all remaining CLI args, from the 3rd one to the last one."

Otherwise, comments should be self-explanatory. If not, justcontact us :)

Now type

$>source ~/.bash_profile
Enter fullscreen modeExit fullscreen mode

So that your terminal will be aware of what changed inside your.bash_profile.

Usage

Open your terminal

$> cnra myapp 7.0.0--minimal-d=postgresql
Enter fullscreen modeExit fullscreen mode

1st CLI arg is "myapp" : the name of the new app
2nd CLI arg is 7.0.0 : the version of Rails you want to try
3rd CLI arg is --minimal -d=postgresql : PostGre is a production-ready database you can easily use locally.

Note that--minimal and-d=postgresql are optionals.

Going further

We personally like the minimal flag (to avoid all the default gems we probably won't need), and the "postgresql" database - a production-ready, widely used database in the Ruby-on-Rails world. So we use another shortcut, based on the previous one.

cnra7mp(){  cnra myapp 7.0.0--minimal-d=postgresql}
Enter fullscreen modeExit fullscreen mode

All we have to do now each time we want to try something with Rails is the following :

$/workspace> cnra7mp$/workspace/myapp> bin/rails server
Enter fullscreen modeExit fullscreen mode

Andvoilà ! A new Rails application up and running, no need to create the database, or build a default welcome page : our app is ready for experimentations.

All available options

If you need to know all the options when creating a new Rails application, seehttps://www.bootrails.com/blog/rails-new-options/

Enjoy !

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Rails & JS dev. Build products.
  • Location
    Nantes, France.
  • Joined

More fromDavid Boureau

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp