希望这个文件足以解决问题。所有工作我都无法保存这篇文章。我无法保存帖子。没有路线匹配[POST]“/ posts/new”
路线:
Rails.application.routes.draw do
root 'posts#index'
resources :posts
end
post_controller:
class PostsController < ApplicationController
def index
@posts = Post.all
end
def show
@post = Post.find(params[:id])
end
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
if @post.save
flash[:notice] = "Successfully created post!"
redirect_to post_path(@post)
else
flash[:alert] = "Error creating new post!"
render :new
end
end
private
def post_params
params.require(:post).permit(:author, :title, :summary, :body)
end
end
请从“回扣路线” – David
发送输出'new'应该是'GET'请求而不是职位(POST请求)。 – fanta
前缀动词URI模式控制器#动作 root GET/posts#index posts GET /posts(.:format)posts#index POST /posts(.:format)posts#create new_post GET/posts/new(.:格式)posts#new edit_post GET /posts/:id/edit(.:format)posts#edit post GET /posts/:id(.:format)posts#show –