我不得不通過視頻和主題之間的關聯一個的has_many,與topicable作爲獨立資源。我想有使只有topicable協會被刪除,而不是視頻,也不是主題的鏈接。這是我迄今所做的:爲什麼這會刪除視頻資源?
在我的routes.rb:
resource :topicable, :only => :destroy
在我topicables控制器:
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, :method => :delete, :class => 'topic_delete' %>
這樣就刪除了相關聯,而且視頻......這不是我想做的事情。我怎樣才能解決這個問題?
UPDATE:
這是我的視頻模式:
has_many :topicables, :dependent => :destroy
has_many :topics, :through => :topicables
這是所有的在topicable模式:
belongs_to :video
belongs_to :topic
注意:這似乎並不有什麼做:依賴=>:摧毀
我有這個在我的視頻模式分配主題作爲虛擬屬性。這可以幫助:
attr_accessor :topic_names
after_save :assign_topics
def assign_topics
if @topic_names
self.topics << @topic_names.map do |name|
Topic.find_or_create_by_name(name)
end
end
end
顯示Topicable模型 – fl00r 2011-04-01 19:01:03
和你topicable模式? – 2011-04-01 19:02:07
你還沒有分化'@ video'來重定向 – fl00r 2011-04-01 19:03:50