ruby on rails - ActiveRecord::RecordNotFound in ArticlesController#show Couldn't find Article with 'id'=edit -
i getting error when got articles/edit.
when should getting error:
my code:
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 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
my edit.html.erb :
<h1>edit existing article</h1> <% if @article.errors.any? %> <h2>the following errors informing if don't these articles not edited</h2> <ul> <% @article.errors.full_messages.each |msg| %> <li> <%= msg %> </li> <% end %> </ul> <% end %> <%= form_for @article |f| %> <p> <%= f.label :title %> <%= f.text_field:title %> </p> <p> <%= f.label :description %> <%= f.text_area :description %> </p> <p> <%= f.submit %> </p> <% end %>
my new.html.erb :
<h1>create article</h1> <% if @article.errors.any? %> <h2>the following errors informing if don't these articles not created</h2> <ul> <% @article.errors.full_messages.each |msg| %> <li> <%= msg %> </li> <% end %> </ul> <% end %> <%= form_for @article |f| %> <p> <%= f.label :title %> <%= f.text_field:title %> </p> <p> <%= f.label :description %> <%= f.text_area :description %> </p> <p> <%= f.submit %> </p> <% end %>
my routes.rb:
resources :articles root 'pages#home' 'about', to: 'pages#about'
ask me more files if helps
then that's cause of error. 'edit' page requires id param otherwise. in controller:
def edit @article = article.find(params[:id]) end
it needs params[:id]
so need use /articles/id/edit
(replace id actual id)
Comments
Post a Comment