我试图设置一个后期编辑页面,其中包含编辑和删除帖子的链接。我有麻烦,因为我的编辑控制器似乎没有收到我发送的参数。我已经将它们打印在页面上以确保它们在那里,并且它可以正确显示,但是当我单击editlink时,我会得到ActiveRecord::RecordNotFound
Couldn't find Article with 'id'=
。Rails 4,控制器没有收到参数
这里与链接的观点:(正确article.id显示在这一个)
<div id= "articles-index">
<div class = "row">
<% @article.each do |article| %>
<div class="row">
<div class = "container">
<p><%= link_to article.title, article %> | <%= article.updated_at.strftime("%e. %b %Y, %H:%M") %> | <%= link_to 'edit', articles_update_path(article.id) %> | delete</p>
<h2><%= article.id %></h2>
</div>
</div>
<% end %>
</div>
</div>
文章控制器:(...的是我编出更多的代码,因为它是不相关的这个问题)
class ArticlesController < ApplicationController
...
def update
@article = Article.find(params[:id])
end
def manage
@article = current_user.articles
@article = current_user.articles.order('id DESC')
end
...
def article_params
params.require(:article).permit(:id, :title, :body, :user_id)
end
end
路线:
get 'articles/edit'
get 'articles/destroy'
get 'articles/manage'
get 'articles/show'
get 'articles/index'
get 'articles/new'
get 'articles/update'
get 'articles/search'
get 'articles/create'
get 'sessions/destroy'
get 'sessions/new'
get 'users/new'
resources :users
resources :sessions
resources :articles
不是什么愚蠢的像params ['id']是吗? –
我查看文章时使用完全相同的语法,它的工作原理是'def show @article = Article.find(params [:id]) end',ony那里的视图代码是'<%= link_to article.title,文章%>' –
你可以发布你的文章路线吗? – Vucko