简体   繁体   English

如何获得此资源的正确ID?

[英]How do I get the correct id of this resource?

I have a has_many, through association between videos and topics with topicables as the independent resource. 我有一个has_many,是通过视频和主题之间的关联将主题作为独立资源。 I want to have a link that deletes that specific topicable record aka the association and NOT the video NOR the topic. 我想要一个链接,该链接删除该特定主题记录(又名关联),而不是视频或主题。

I have this method in my topicables controller: 我的topics控制器中有此方法:

def destroy
  @topicable = Topicable.find(params[:id])
  @topicable.destroy
  respond_to do |format|
    format.html {redirect_to @video}
    format.js
  end
end

I call the above method with this link in my video show view: 我在视频播放视图中使用此链接调用上述方法:

<%= link_to "x", topicable_path(@topicable), :method => :delete, :class => 'topic_delete' %>

However, I get this error: 但是,我收到此错误:

ActiveRecord::RecordNotFound in TopicablesController#destroy

Couldn't find Topicable with ID=474

This is because 474 is the id of the video and not the id of the association between the topic and video in the topicable table. 这是因为474是视频的ID,而不是可主题化表中主题和视频之间的关联的ID。 What is wrong with my destroy method above and how can I fix it? 我上面的destroy方法有什么问题,我该如何解决?

我不确定,我必须测试一些东西,但是请您可以尝试一下:

<%= link_to "x", @topicable, :method => :delete %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM