こんにちは!kossyです!
スルガ銀行の不正融資問題について、第三者委員会の報告書が出来上がったようです。
kabumatome.doorblog.jp
チラっとしか目を通していませんが、「これはネタなのか?」と思う文章が散見されました。笑
ノルマに関してのコメント「例えれば、釣り堀に魚が10匹いないのに10匹とってこいといわれる状況」が
個人的には一番印象に残っています。
さて、今回はannotateの使い方についてブログに残したいと思います。
このgemを使用することで、「あれ、このカラムのデータ型ってなんだったっけ」とか
「ルーティングどんな感じに設定してたっけ。$ rails routesだ!」とかしなくてもよくなります。
以下、導入手順です。
モデルにテーブル構造の表示をしたい場合
gemfile group :development do gem 'annotate' <= 追記 end $ bundle install $ bundle exec annotate app/models/モデル名.rb 以下の記述が追加される # == Schema Information # # Table name: モデル名 #(以下はテーブル構造によって異なります) # id :bigint(8) not null, primary key # content :text # picture :string # kind :string # created_at :datetime not null # updated_at :datetime not null #
routes.rbファイルの中身にrails routesの実行結果を表示したい場合(gemfileへの追記、bundle installは済んでいるものとする)
$ bundle exec annotate --routes => config/routes.rb annotated. config/routes.rb (以下は設定したルーティングによって異なります) # == Route Map # # Prefix Verb URI Pattern Controller#Action # confirm GET /confirm/:id(.:format) posts#confirm # posts POST /posts(.:format) posts#create # edit_post GET /posts/:id/edit(.:format) posts#edit # post GET /posts/:id(.:format) posts#show # PATCH /posts/:id(.:format) posts#update # PUT /posts/:id(.:format) posts#update # root GET / posts#new #
テーブル構造が変わるたびにannotateをするのは面倒なので、
rails db:migrateされた時にannotateが走るように設定してみましょう。
$ rails g annotate:install => Running via Spring preloader in process 1029 create lib/tasks/auto_annotate_models.rake
導入するのは非常に簡単ですのでみなさんぜひ使ってみてください。