[英]How do I get the correct id of this resource?
我有一个has_many,是通过视频和主题之间的关联将主题作为独立资源。 我想要一个链接,该链接删除该特定主题记录(又名关联),而不是视频或主题。
我的topics控制器中有此方法:
def destroy
@topicable = Topicable.find(params[:id])
@topicable.destroy
respond_to do |format|
format.html {redirect_to @video}
format.js
end
end
我在视频播放视图中使用此链接调用上述方法:
<%= link_to "x", topicable_path(@topicable), :method => :delete, :class => 'topic_delete' %>
但是,我收到此错误:
ActiveRecord::RecordNotFound in TopicablesController#destroy
Couldn't find Topicable with ID=474
这是因为474是视频的ID,而不是可主题化表中主题和视频之间的关联的ID。 我上面的destroy
方法有什么问题,我该如何解决?
我不确定,我必须测试一些东西,但是请您可以尝试一下:
<%= link_to "x", @topicable, :method => :delete %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.