1
Wie ich oben sagte. Ich benutze meinen Code so.redirect_to @article funktioniert nicht. article_url nicht definiert
class ArticlesController < ApplicationController
def show
@article = Article.find(params[:id])
end
def new
end
def create
@article = Article.new(article_params)
@article.save
redirect_to @article
end
private
def article_params
params.require(:article).permit(:title, :text)
end
end
Aber es funktioniert immer nicht. Ich habe keine Ahnung und andere Fragen nützen nichts. Das ist meine Vorlage.
<%= form_for :article,url: articles_path 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 %>
Sie verwenden den falschen Pfad: 'articles_path' ist für die Indexaktion,' article_path' ist für die show action - und Sie haben keine Indexaktion. Rake Routen und sehe, was dir das sagt. –