I do something like a blog by tutorial, when reading or deleting a post, I get this error

enter image description here I understand that the matter is in the parameters, but I cannot solve the problem Code: Controller

class ArticlesController < ApplicationController def show @article = Article.find(params[:id]) end def new @article = Article.new end def create @article = Article.new(articles_params) @article.save redirect_to '/' end def destroy @article = Article.find(params[:id]) @article.destroy! redirect_to 'root' end end private def articles_params params.require(:article).permit(:title,:text) end 

Viewport

 new.erb <%= 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 %> show.erb <p> <strong>Title:</strong> <%= @article.title %> </p> <p> <strong>Text:</strong> <%= @article.text %> </p> index.erb <h1>Listing articles</h1> <table> <tr> <th>Title</th> <th>Text</th> </tr> <%= link_to 'New Post', new_articles_path %> <% @article.each do |article| %> <tr> <td><%= article.title %></td> <td><%= article.text %></td> <td><%= link_to 'Show', articles_path(article),controller: 'articles' %></td> <td><%= link_to 'Destroy', articles_path(article), method: :delete, data: {confirm: 'Are you sure?' }%></td> </tr> <% end %> </table> 

Home page enter image description here

Links

 <a href="/articles/new">New Post</a> <tr> <td>asdafsd</td> <td>asdasdczxc</td> <td><a controller="articles" href="/articles.1">Show</a></td> <td><a controller="articles" data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/articles.1">Destroy</a></td> </tr> <tr> <td>sasdasdzxcxv</td> <td>dsfsvc</td> <td><a controller="articles" href="/articles.2">Show</a></td> <td><a controller="articles" data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/articles.2">Destroy</a></td> </tr> <tr> <td>sasdasdzxcxv</td> <td>dsfsvcx</td> <td><a controller="articles" href="/articles.3">Show</a></td> <td><a controller="articles" data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/articles.3">Destroy</a></td> 

Rake

  Prefix Verb URI Pattern Controller#Action new_articles GET /articles/new(.:format) articles#new edit_articles GET /articles/edit(.:format) articles#edit articles GET /articles(.:format) articles#show PATCH /articles(.:format) articles#update PUT /articles(.:format) articles#update DELETE /articles(.:format) articles#destroy POST /articles(.:format) articles#create root GET / welcome#index 
  • Try adding the parameter controller: 'articles' link_to 'Destroy' line, as in the line above. - aleks.andr
  • This does not work, I have a strong impression that when I click on the show or destroy link, no parameters are passed, because the error says "Couldn't find Article with 'id' =" where there is no parameter value: id, I think it should be " Couldn't find Article with 'id' = 5 "or something like that. Added homepage just in case - Lukashman
  • @Lukashman open the page code and see what the links look like. add the rake routes result to the question. - Mikhail Vaysman
  • @Mikhail Vaysman added. - Lukashman
  • one
    @Lukashman still add config/routes.rb - Mikhail Vaysman

1 answer 1

You have written resource , but you need resources (plural).

  • Thank you very much! Replaced resources in the routes, at first the truth did not work, but then I realized from the logs that I needed to replace the index view to the show and destroy articles_path (article) links with article_path (article). Shame, because of one letter itself so much torment done. You can tell what the differences resourse and resources are, and in what cases they are used, I read that it comes from RESTful services, but I would like to know more, thank you very much in advance! - Lukashman
  • @Lukashman do you know Ruby yourself? If you have a new question, ask it using the " Ask a Question " button. If you need to specify the context, give a link to this question. - Mikhail Vaysman
  • I got acquainted in general terms, switched to it from Java, in any case, thanks again. - Lukashman
  • @Lukashman is better to start with Ruby, and then go to Rails. - Mikhail Vaysman