3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ある社内SEとRailsのこれだけやっとけコマンド集

Posted at

Railsでよく使うコマンド集まとめ

★サーバー起動(開発環境)
	bundle exec rails s
★サーバー停止
	Ctrl+C
★railsコンソール起動
	bundle exec rails c
★コントローラー、ビュー作成
	bundle exec rails g controller ●●● index show new edit destroy
	bundle exec rails g controller ●●● index
★モデル作成。マイグレーションファイルも作られる。
すでにテーブルができていて、作りたくない場合は--migration=false
	bundle exec rails g model ●●●
	bundle exec rails g model ●●●--migration=false
★モデル削除
	bundle exec rails destroy model ●●●
★テーブル項目編集、変更
	マイグレーションファイルのみ作成。クラス名は行う処理+テーブル名が原則
	bundle exec rails g migration RenameColumn●●●
	bundle exec rails g migration AddColumn●●●
	bundle exec rails g migration AddIndex●●●
	上記で作成したマイグレーションファイルを編集して、テーブル項目確定
★データベースへマイグレーションする
	bundle exec rails db:migrate
★テーブルに初期データを入れる
	bundle exec rails db:seed 
★特定のシードファイルを入れたい場合
	bundle exec rails r db/seeds/●●●_add.rb		
★ルーティングの定義確認(すごい使う)
	bundle exec rails routes
★schema.rb にテーブルとActiveRecordを紐付ける情報が記載されている。

★テーブルにカラム追加・削除変更手順
	テーブル名、追加したいカラム名、型を記述
	●カラム追加の書き方
	add_column :bbinfos, :udp_recieve_at, :datetime
	●カラム削除の書き方
	remove_column :article, :title, :text

	migration実行
	bundle exec rails db:migrate

終わりに

たぶん上のコマンドだけで、軽いWebサービス1つ作れますよ♪
手で追加すればいいやんって人もいると思いますが、テストファイルを同時に作ってくれたり
関連のあるファイル作ってくれたりしてるので、せっかくRails使ってるんなら、
線路に乗っていきましょう。私が使ってるリアルチートシートです。良ければご利用下さいませ。

3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?