LoginSignup
1
0

More than 5 years have passed since last update.

rails generate controllerで同時にいくつ作れるのか気になった話

Posted at

オレ generate スキ

コマンド一つで必要なものがザッと作れるgenerate、ほんと好き。
生産性が高いってこういうことなんですかね?と入門したばかりなのに楽しくて仕方がない。
そこでふと気になったんですよ、「アレっていくつくらい同時に作れるのかなぁ?」って。
そんな小学生のような疑問を大切にしていきたい今日このごろ。

環境

  • cloud9
  • Rails 5.2.2

とりあえずアルファベットを1巡してみよう

ググって1ページ目にそれっぽいものがなかったのでとりあえずアルファベット並べてみました。

$ rails generate controller sample a b c d e f g h i j k l m n o p q r s t u v w x y z

こんなに同時に作るプロジェクトあるのかなぁ…。
知的好奇心を満たしたいだけなので疑問をスポイル。
流石に多すぎって怒られるかなぁ?と思いながらEnterぽちー!

$ rails generate controller sample a b c d e f g h i j k l m n o p q r s t u v w x y z
Running via Spring preloader in process 4430
      create  app/controllers/sample_controller.rb
       route  get 'sample/a'
get 'sample/b'
get 'sample/c'
get 'sample/d'
get 'sample/e'
get 'sample/f'
get 'sample/g'
  :
 (中略)
  :
      invoke    coffee
      create      app/assets/javascripts/sample.coffee
      invoke    scss
      create      app/assets/stylesheets/sample.scss

マ?
通っちゃったよ。
じゃあもう1巡、つまりアルファベット52文字なら?

$ rails generate controller sample a b c d e f g h i j k l m n o p q r s t u v w x y z aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz                             
Running via Spring preloader in process 4570
      create  app/controllers/sample_controller.rb
       route  get 'sample/a'
get 'sample/b'
get 'sample/c'
get 'sample/d'
get 'sample/e'
get 'sample/f'
get 'sample/g'
  :
 (中略)
  :
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/sample.coffee
      invoke    scss
      create      app/assets/stylesheets/sample.scss

ウッソだろお前!
ということで、そこそこたくさんを一回でgenerateできそうです。

おまけ:最後の一撃はせつない

消す時はgenerateをdestroyに書き換えて実行。

$ rails destroy controller sample a b c d e f g h i j k l m n o p q r s t u v w x y z aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz

まぁブランチ切っといて、ブランチごと捨てる方が楽だけどさ

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0