在Rails(5.1)应用程序中,我有以下路径
edit_admin_topics_active GET /admin/topics/active/:id/edit(.:format) admin/topics/active#edit
admin_topics_active PATCH /admin/topics/active/:id(.:format) admin/topics/active#update
PUT /admin/topics/active/:id(.:format) admin/topics/active#update
以下控制器
class Admin::Topics::ActiveController < Admin::TopicsController
...
def edit
@topic = Topic.find_by_slug(params[:id])
end
def update
...
end
...
end
以下视图
#app/views/topics/active/edit
<%= form_for @topic, url: admin_topics_active_path(@topic) do |f| %>
<%= render 'form', f: f, topic: @topic %>
<% end %>
开发时一切正常,但是当我尝试运行以下(简化)规范时(RSpec 3.7)
RSpec.feature 'Update a topic', type: :feature do
let(:topic) { create(:topic) }
scenario 'the updated topic is included in the list of topics' do
visit edit_admin_topics_active_path(topic)
submit_form
expect(page).to have_content(topic.code)
end
end
我得到了
::的ActionView模板::错误: 没有路由匹配{:action =&gt;“update”,:controller =&gt;“admin / topics / active”,:id =&gt; nil},缺少必需的密钥: [:ID]
知道这是怎么回事吗?