Help us understand the problem. What is going on with this article?

Ruby on rails を使ってCRUDを実装するまで(記事作成、詳細表示、編集、削除)

Ruby on rails を使ってCRUDを実装するまで(プロジェクト作成~一覧表示)の続き

前回までのおさらい

新規プロジェクトを作成
ページの表示

今回の範囲
scaffoldを使用する
ページの表示

今回作るWebアプリケーションの足場を作る

今回作るMemoの足場を作る
Railsには足場を作るためのScaffoldという仕組みが用意されているのでこれを利用します。

$cd blog
$rails g scaffold Memo title:string body:text

以下が出力されればOKです。

Running via Spring preloader in process 13466
      invoke  active_record
      create    db/migrate/20190409064133_create_memos.rb
      create    app/models/memo.rb
      invoke    test_unit
      create      test/models/memo_test.rb
      create      test/fixtures/memos.yml
      invoke  resource_route
       route    resources :memos
      invoke  scaffold_controller
      create    app/controllers/memos_controller.rb
      invoke    erb
      create      app/views/memos
      create      app/views/memos/index.html.erb
      create      app/views/memos/edit.html.erb
      create      app/views/memos/show.html.erb
      create      app/views/memos/new.html.erb
      create      app/views/memos/_form.html.erb
      invoke    test_unit
      create      test/controllers/memos_controller_test.rb
      create      test/system/memos_test.rb
      invoke    helper
      create      app/helpers/memos_helper.rb
      invoke      test_unit
      invoke    jbuilder
      create      app/views/memos/index.json.jbuilder
      create      app/views/memos/show.json.jbuilder
      create      app/views/memos/_memo.json.jbuilder
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/memos.coffee
      invoke    scss
      create      app/assets/stylesheets/memos.scss
      invoke  scss
      create    app/assets/stylesheets/scaffolds.scss

これでmigrationファイル

db/migrate/YYYYMMDDHHMMSS_create_posts.rb
class CreatePosts < ActiveRecord::Migration[5.2]
  def change
    create_table :posts do |t|
      t.string :title
      t.text :body

      t.timestamps
    end
  end
end

も作成されたので、

$rails db:migrate

以下のように出力されればOKです。

== 20190409064133 CreateMemos: migrating ======================================
-- create_table(:memos)
   -> 0.0015s
== 20190409064133 CreateMemos: migrated (0.0016s) =============================

これでアプリケーションを作成するための土台ができたので確認します
http://localhost:3000/memos
にアクセスすると
スクリーンショット 2019-04-09 15.46.48.png
このような画面が表示されていればOKです。

もう、この時点でWebアプリケーションとしては完成になります。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした