前提・実現したいこと No route matches [POST] "/posts/new"を解決したい
RubyonRails初心者です。投稿アプリの作成中、記事の登録アクションを実装しようとしたら下記のエラーがでました。
googleで調べてみたのですが、調べ方が下手なのかなかなか解決できない状況です。。
発生している問題・エラーメッセージ
投稿のボタンを押すと下記エラーとなります。
エラーメッセージ
Routing Error
No route matches [POST] "/posts/new"
該当のソースコード
#posts_controller.rb class PostsController < ApplicationController def index @post = Post.new end def show end def new end def create post = Post.new(post_params) post.save! redirect_to posts_url, notice: "「#{post.name}を投稿しました。」" end def edit end private def post_params params.require(:post).permit(:name, :article) end end
#routes.rb Rails.application.routes.draw do root to: 'posts#index' resources :posts end
#index.html.slim h1 投稿一覧 = link_to '新規投稿', new_post_path, class: "btn btn-primary"
#new.html.slim h1 新規投稿 .nav.justify-content-end = link_to '一覧', posts/path, class: 'nav-link' = form_with model: @post, local: true do |f| .form-group = f.label :name = f.text_field :name, class: 'form-control', id: 'post_name' .form-group = f.label :article = f.text_area :article, rows: 5, class: 'form-control', id: 'post_article' = f.submit nil, class: 'btn btn-primary'
試したこと
なにが間違ってるのか調べてもわからず仕舞いです、、
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答3件
あなたの回答
tips
プレビュー