在尝试提交帖子后,我收到了一个令人困惑的路由错误。错误是No route matches [POST] "/blog",尽管它在routes.rb中。
这是我的路由文件:
Rails.application.routes.draw do
get 'welcome/index'
get '/blog', to: 'posts#post', as: :post
get '/geobot', to: 'welcome#geobot', as: :geobot
get "/blog/show/:id", to: 'posts#show'
get '/blog/new', to: 'posts#new', as: :new
root 'welcome#index'
end 和post控制器:
class PostsController < ApplicationController
def post
end
def new
end
def create
@post = Post.new(post_params)
@post.save
redirect_to @post
end
def show
@post = Post.find(params[:id])
end
private
def post_params
params.require(:post).permit(:title, :body)
end
end 发布于 2016-10-09 11:00:57
你必须把你的route.rb
...
post '/blog', to: 'posts#post', as: :post
...第一个词是方法
发布于 2017-09-24 01:50:02
你定义了什么?( GET请求)
get '/blog',to:'posts#post',as::post
但它需要POST类型的路由'/blog‘。所以只需要定义它
博客post‘/
’,to:'posts#create',as::post
https://stackoverflow.com/questions/39939550
复制相似问题