没有路由匹配 [POST] "/articles/new"; [英] No route matches [POST] "/articles/new"
问题描述
当我尝试提交表单时,它给了我错误
When I try to submit the form its giving me the error
No route matches [POST] "/articles/new"
文件是:new.html.erb
此文件包含带有文本字段和文本区域的表单:
the files are: new.html.erb
this file which contains the form with a text field and text area:
<%= form_for :article, url: articles_path do |f| %>
这里的 url: 是匹配创建的 post 请求
here the url: is to match post request which is a create
表单标题
<%= f.label :title %><br>
表单的文本字段
<%= f.text_field :title %></p>
表单标题
<%= f.label :text %><br>
表单的文本区域
<%= f.text_area :text %></p>
<p>
<%= f.submit %>
</p>
<% end %>
路由文件是
Rails.application.routes.draw do
resources :article
end
控制器是控制器及其方法 new 和 create
controller is the controller with its methods new and create
每当我提交表单时,它都会出现错误,即使我使用了 URL:articles_path 作为默认发布请求,我也在表单中使用了 @articles,但它给了我同样的错误.我是 Rails 的新手,所以我尝试了很多方法,但找不到解决方案
whenever I submit the form its giving the error, even I used the URL: articles_path which for default post request, I used @articles also in the form but it is giving me the same error. I am new to the Rails so I tried many ways but I could not find the solution
class ArticlesController < ApplicationController
def new #new method which is a get request
end
def create #create method which is a post request
end
end
每当我提交表单时都会出现错误,即使我使用了 url:articles_path 作为默认发布请求.我一直在
whenever I submit the form its giving the error, even I used the url: articles_path which for default post request. and I kept
def create
end
在控制器中
推荐答案
更改:
resources :article
到:
resources :articles #plural
这样它就会映射到:
articles_path POST /articles(.:format) articles#create
这篇关于没有路由匹配 [POST] "/articles/new";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!