我得到一個錯誤,當我坐進文章/編輯。的ActiveRecord :: RecordNotFound在ArticlesController#顯示找不到文章與「ID」 =編輯
時,我應該得到這個錯誤:
我的代碼:
articles_controller:
class ArticlesController < ApplicationController
def new
@article = Article.new
end
def edit
@article = Article.find(params[:id])
end
def create
@article = Article.new(article_params)
if @article.save
flash[:notice] = "Article was submitted succsefully"
redirect_to (@article)
else
render :new
end
end
def show
@article = Article.find(params[:id])
end
private
def article_params
params.require(:article).permit(:title, :description)
end
end
我edit.html.erb:
<h1>Edit the existing article</h1>
<% if @article.errors.any? %>
<h2>The following errors are informing you that if you don't do these then
your articles will not be edited</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li> <%= msg %> </li>
<% end %>
</ul>
<% end %>
<%= form_for @article do |f| %>
<p>
<%= f.label :title %>
<%= f.text_field:title %>
</p>
<p>
<%= f.label :description %>
<%= f.text_area :description %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
我new.html.erb:
<h1>Create an article</h1>
<% if @article.errors.any? %>
<h2>The following errors are informing you that if you don't do these then
your articles will not be created</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li> <%= msg %> </li>
<% end %>
</ul>
<% end %>
<%= form_for @article do |f| %>
<p>
<%= f.label :title %>
<%= f.text_field:title %>
</p>
<p>
<%= f.label :description %>
<%= f.text_area :description %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
我的routes.rb:
resources :articles
root 'pages#home'
get 'about', to: 'pages#about'
向我要更多的文件,如果有幫助
顯示你在routes.rb中有什麼 –
你使用了什麼查詢參數。 資源:您可以通過URL – MisterCal
DANIL斯佩蘭斯基在這裏它是回覆文章 根「頁面#家」 GET「約」,到:「網頁#關於」 –