0
0

More than 3 years have passed since last update.

Web制作の一連の流れ 〜メインとなるモデル

Posted at

手順 メインモデル作成

① rails g model (モデル名)
② マイグレーションファイルに必要なカラムを記述、Userモデルと紐づける必要があるなら、
t.references :user, foreign_key: true
みたいに記述
③ rails db:migrateでテーブル作成

モデル

① バリデーション、アソシエーションの作成
② 写真等の投稿がある場合
  ⅰ) Gemfileにgem 'mini_magick'  gem 'image_processing', '~> 1.2'を記述して
bundle install
ⅱ) rails active_storage:installでActive Storage導入してrails db:migrate
ⅲ) そのモデルにバリデーション、アソシエーションの設定
    has_one_attached :image
    validates :image, presence: true

コントローラー、ルーティング

① 使用するアクションの記述
コントローラ
def index
end

ルーティング
resources :(コントローラー名) only: :index
みたいに

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