■
routes.rb
Rails.application.routes.draw do get 'posts', to: 'posts#index' get 'posts/new', to: 'posts#new' end
書いてから
$ rails routes Prefix Verb URI Pattern Controller#Action posts GET /posts(.:format) posts#index posts_new GET /posts/new(.:format) posts#new (以下省略)
rails routesでルートチェック
で、コントローラーを作る
class PostsController < ApplicationController def index @posts = Post.all end def new end end
で、対応するビューを作る
ビューファイルはapp/views/コントローラー名
ディレクトリに格納され、ファイル名はアクション名.html.erb
となります。したがって、今回作成するのは、app/views/posts/new.html.erb
です。