LoginSignup
0
0

More than 5 years have passed since last update.

Rails 序盤シート

Last updated at Posted at 2019-04-27
  • 少しずつ更新します。

RubyMineに Version Control パネルを出す

  • ⌘ + 9 で出ます。

rails g 時の自動生成を制御

config/application.rb
class Application < Rails::Application
    config.load_defaults 5.2

    # 以下を追記
    config.generators do |g|
      # 「rails g」時の自動生成を制御
      g.assets false         # css,jsを生成しない
      g.helper false         # ヘルパーを生成しない
      g.test_framework false # テストファイルを生成しない
    end
  end
  • テストファイルは後ほど作りますが、個人的に rails g 時には要らなかったので、こう書いています。

コントローラー生成時にアクションも指定する

$ rails g controller books index edit show new
  • 例として books_controller を生成し、同時に4つのアクションを指定しました。
  • これでビューも一緒に作られます(ルーティングも記述されますが、それは生成後に手で直すことも多いですかね)

モデル生成時に外部キーを指定する

  • 例: teams モデル生成時に、 name カラムと league_id (外部キー) を指定する。
$ rails g model team league:references name:string

トップページのルーティング設定

  • 例として books_controllerindex アクションにマッピングします。
  • root メソッドは、 routes.rb の最下部に記述します。
config/routes.rb
Rails.application.routes.draw do
  resources :books

  (中略)

  root to: 'books#index'
end

参考

0
0
0

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
0
0