Home Rails - destroy associations from object with condition
 I have an object @foo with a :has_many associations to bar and I want before foo is destroyed all association objects from bar will be destroyed too if the bar has the property type = test. the following code is working and the foo object is deleted but the bars are still there: (if I dont't use the condition .where(type: "test) all bars will be deleted)  def destroy @foo.bars.each{|b| b.update_attribute(:blub_id, nil)} @foo.bars.where(type: "test").destroy_all @foo.destroy respond_to do |format| format.html { redirect_to foo_url, notice: 'Foo was successfully destroyed.' } format.json { head :no_content } end end