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

More than 3 years have passed since last update.

初歩中の初歩!railsでのモデル・コントローラー作成方法

Last updated at Posted at 2020-08-09

#モデル作成方法

rails g モデル名(単数)

マイグレーション型一覧
・string : 文字列
・text : 長い文字列
・integer : 整数
・float : 浮動小数
・decimal : 精度の高い小数
・datetime : 日時
・timestamp : タイムスタンプ
・time : 時間
・date : 日付
・binary : バイナリデータ
・boolean : Boolean

class CreateExercises < ActiveRecord::Migration[6.0]
  def change
    create_table :テーブル名(複数形) do |t|
    t.migrate型 :カラム名(単数)
      t.string :part
      t.text :url
      t.integer :level
      t.timestamps
    end
  end
end

ここまで設定できたらお決まりの

rails db:migrate

== 20200809105002 CreateExercises: migrating ==================================
-- create_table(:exercises)
   -> 0.0244s
== 20200809105002 CreateExercises: migrated (0.0245s) =========================

こんな感じの表示がでれば成功

#コントローラー作成

rails g controller コントローラー名 アクション名

※コントローラー名は大文字始まりの複数形
下記のような表示がでれば成功

Running via Spring preloader in process 65910
      create  app/controllers/exercises_controller.rb
       route  get 'exercises/index'
      invoke  erb
      create    app/views/exercises
      create    app/views/exercises/index.html.erb
      invoke  test_unit
      create    test/controllers/exercises_controller_test.rb
      invoke  helper
      create    app/helpers/exercises_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    scss
      create      app/assets/stylesheets/exercises.scss
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?