From 94b73faf85bcc449694b9011ed084247d7808ff6 Mon Sep 17 00:00:00 2001 From: Alan Bradburne Date: Thu, 23 Feb 2012 11:35:34 +0000 Subject: [PATCH] Change clear channel to not do a find-all before deleting feeds. --- app/controllers/channels_controller.rb | 2 +- app/models/channel.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index 7ef52ba..2734222 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -38,7 +38,7 @@ class ChannelsController < ApplicationController # clear all data from a channel def clear channel = current_user.channels.find(params[:id]) - channel.feeds.delete_all + channel.delete_feeds channel.update_attribute(:last_entry_id, nil) redirect_to channels_path diff --git a/app/models/channel.rb b/app/models/channel.rb index b941021..28be06a 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -10,6 +10,7 @@ class Channel < ActiveRecord::Base after_create :set_initial_default_name before_validation :set_default_name + after_destroy :delete_feeds validates :name, :presence => true, :on => :update @@ -22,7 +23,11 @@ class Channel < ActiveRecord::Base end def field_label(field_number) - self["field#{field_number}"] + self.attributes["field#{field_number}"] + end + + def delete_feeds + Feed.delete_all(["channel_id = ?", self.id]) end private