Делаю что-то наподобие блога по туториалу, при чтении или удалении записи, получаю такую ошибку
Понимаю, что дело в параметрах, но решить проблему не могу
Код:
Контроллера
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
Вьюшек
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>
Ссылки
<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
link_to 'Destroy'
добавить параметрcontroller: 'articles'
, как в строке выше. – aleks.andr 11 фев '17 в 19:12rake routes
в вопрос. – Mikhail Vaysman 12 фев '17 в 2:18config/routes.rb
– Mikhail Vaysman 12 фев '17 в 2:38