I have a has_many, through association between videos and topics with topicables as the independent resource. I want to have开发者_如何学C 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:
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. What is wrong with my destroy
method above and how can I fix it?
I'm not sure about that, i would have to test some things, but can you try this please :
<%= link_to "x", @topicable, :method => :delete %>
精彩评论