<%= form_tag("/posts/create") do%> . . . <% end %>
でnew action を create actionに form_tagで送り create action から /posts/indexにredirectしたいのですが以下のエラーが出ます
Unknown action The action 'create' could not be found for PostsController
自分のRuby on Railsのコード
<%= form_tag("/posts/create") do %> <div class="form"> <div class="form-title"> <input name="title"> </div> <div class="form-body"> <textarea name="content"></textarea> <br> <input type="submit" value="投稿"> </div> </div> <% end %>
class PostsController < ApplicationController def index @posts = Post.all end def show @post = Post.find_by(id: params[:id]) end def new end def create @post = Post.new(title: params[:title], content: params[:content]) @post.save redirect_to("/posts/index") end end
get "posts/index" => "posts#index" get "posts/new" => "posts#new" get "posts/:id" => "posts#show" post "posts/create" => "posts#create"
何が原因なのでしょうか?
あなたの回答
tips
プレビュー