Ich brauche eine Hilfe. Ich erhalte den folgenden Fehler beim Veröffentlichen der Formulardaten mit ROR.Routing-Fehler beim Senden des Formulars mit ROR
No route matches [POST] "/articles/new"
Rails.root: C:/Sites/blog
Application Trace | Framework Trace | Full Trace
Routes
Routes match in priority from top to bottom
Helper HTTP Verb Path Controller#Action
Path/Url
articles_path GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article_path GET /articles/new(.:format) articles#new
edit_article_path GET /articles/:id/edit(.:format) articles#edit
article_path GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#up
Ich erkläre meinen Code unten.
new.html.erb:
<%= form_for @article do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
date
Wenn der Benutzer ist diese Form jene Art von Fehler abzulegen coming.My route.rb
Datei ist unten angegeben.
Rails.application.routes.draw do
resources :articles
root 'welcome#index'
end
Mein Controller-Dateicode ist unten angegeben.
class ArticlesController < ApplicationController
def new
end
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article
else
render 'new'
end
end
end
Ich bin mit Rails Version 4.2...
.Please mir helfen, diesen Fehler zu beheben.
Die Standard Rails 'new' Aktion wäre' GET/articles/new', aber die Standard 'create' Aktion wäre' POST/articles' (ohne das '/ new' am Ende); Ihr Formular wird an die falsche URL gesendet. Übrigens, sollte Ihre 'def new'-Controller-Methode' @article = Article.new' nicht enthalten? – GoBusto
Können Sie Ihre Antwort bearbeiten? – subhra