1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

🔧 Ruby on Rails よく使うコマンド【プログラミングノート】

Last updated at Posted at 2025-07-12

🔧 Ruby on Rails よく使うコマンド集

記事の続きです。
RubyとRailsの魅力にハマった話 〜初心者が書くプログラミングノート〜

🏁 基本操作

rails new app_name         # 新しいRailsアプリを作成
cd app_name                # 作成したアプリのフォルダに移動
rails server               # サーバー起動(http://localhost:3000)
rails console              # Railsコンソール起動(データ操作に便利)
rails routes               # ルーティングの一覧を確認

📦 パッケージ管理とバージョン確認

bundle outdated          # 古いGemの一覧を表示
bundle update gem_name   # 特定のGemをアップデート
rails -v                 # Railsのバージョン確認
ruby -v                  # Rubyのバージョン確認
bundle install            # Gemfileの依存パッケージをインストール
bundle update             # パッケージを最新にアップデート
bin/setup                 # 初期セットアップ(初回に便利)

🛠️ ジェネレーター(自動生成)

rails generate scaffold Post title:string body:text
# Postモデル + コントローラ + ビューなどを一括生成

rails generate model User name:string email:string
# モデルのみ作成

rails generate controller Users index show
# コントローラとアクション作成

rails destroy scaffold Post
# 生成したものを取り消す

📂 ファイルアップロード(Active Storage)

rails active_storage:install        # ActiveStorage用のマイグレーション生成
rails db:migrate                    # マイグレーション実行

🗃️ データベース関連

rails db:create           # データベース作成
rails db:migrate          # マイグレーションを実行
rails db:rollback         # マイグレーションを1つ戻す
rails db:seed             # db/seeds.rbを使って初期データを投入
rails db:reset            # DBを初期化(drop → create → migrate → seed)

🧪 テスト(RSpecを使う場合)

bundle exec rspec         # テストを実行(全体)
bundle exec rspec spec/models/user_spec.rb
# 特定のテストファイルだけ実行

💡 その他便利コマンド

rails notes               # コメントで書いたTODOなどを一覧表示
rails about               # Railsバージョンや環境の情報を表示

📘 補足:コマンドのヘルプを見たいとき

rails --help              # railsコマンド全体のヘルプ
rails generate --help     # generateコマンドの詳細
1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?