From 42f560957f441b7ab97c0b65249b01f14d414c37 Mon Sep 17 00:00:00 2001 From: lukemelia Date: Fri, 23 Feb 2007 13:54:38 +0000 Subject: [PATCH] DRY up the feed_controller with a filter. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@455 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/feed_controller.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tracks/app/controllers/feed_controller.rb b/tracks/app/controllers/feed_controller.rb index 9a5eae75..badce178 100644 --- a/tracks/app/controllers/feed_controller.rb +++ b/tracks/app/controllers/feed_controller.rb @@ -10,6 +10,7 @@ class FeedController < ApplicationController skip_before_filter :login_required before_filter :check_token_against_user_word before_filter :prepare_for_feed, :only => [:rss, :text, :ical] + before_filter :identify_contexts, :only => [:text, :ical] # Build an RSS feed def rss @@ -25,11 +26,6 @@ class FeedController < ApplicationController # curl [url from "TXT" link on todo/list] # def text - if params.key?('context') - @contexts = [ @user.contexts.find_by_params(params) ] - else - @contexts = @user.contexts.find_all_by_hide(false, "position ASC") - end headers["Content-Type"] = "text/plain; charset=utf-8" end @@ -38,11 +34,6 @@ class FeedController < ApplicationController # Due dates are supported, and notes are included. # def ical - if params.key?('context') - @contexts = [ @user.contexts.find_by_params(params) ] - else - @contexts = @user.contexts.find_all_by_hide(false, "position ASC") - end headers["Content-Type"] = "text/calendar" end @@ -56,6 +47,14 @@ protected return false end end + + def identify_contexts + if params.key?('context') + @contexts = [ @user.contexts.find_by_params(params) ] + else + @contexts = @user.contexts.find_all_by_hide(false, "position ASC") + end + end def prepare_for_feed condition_builder = FindConditionBuilder.new