From db9d1dc93e19b8555706bb549da8b611d77d3a72 Mon Sep 17 00:00:00 2001 From: francis Date: Fri, 4 Apr 2008 01:59:40 +0000 Subject: Prevent tracking same request twice. --- app/controllers/track_controller.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'app/controllers/track_controller.rb') diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb index 37283d0d9..eda7c60a2 100644 --- a/app/controllers/track_controller.rb +++ b/app/controllers/track_controller.rb @@ -5,7 +5,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: track_controller.rb,v 1.2 2008-04-03 15:29:50 francis Exp $ +# $Id: track_controller.rb,v 1.3 2008-04-04 01:59:40 francis Exp $ class TrackController < ApplicationController @@ -13,14 +13,22 @@ class TrackController < ApplicationController def track_request @info_request = InfoRequest.find_by_url_title(params[:url_title]) @track_thing = TrackThing.create_track_for_request(@info_request) - if self.track_set - flash[:notice] = "You are now tracking this request!" + ret = self.track_set + if ret + flash[:notice] = "You are " + ret + " tracking this request!" redirect_to request_url(@info_request) end end # Generic request tracker - set @track_thing before calling def track_set + if @user + @existing_track = TrackThing.find_by_existing_track(@user.id, @track_thing.track_query) + if @existing_track + return "already" + end + end + @track_thing.track_medium = 'email_daily' @title = @track_thing.params[:title] @@ -40,7 +48,7 @@ class TrackController < ApplicationController @track_thing.tracking_user_id = @user.id @track_thing.save! - return true + return "now" end end -- cgit v1.2.3