Browse files

fixed check if exists method

  • Loading branch information...
1 parent b6f9efb commit 12654e9c5d7e7a45676aeb7e8b47dc94e458ef0d @jeffdonthemic jeffdonthemic committed Aug 24, 2012
View
6 app/controllers/application_controller.rb
@@ -19,11 +19,7 @@ def notifications
# fetch the access token for this user or return the public access token from the database
def current_access_token
- if current_user.nil?
- return SfdcConnection.public_access_token
- else
- return SfdcConnection.member_access_token current_user
- end
+ current_user.nil? ? SfdcConnection.public_access_token : SfdcConnection.member_access_token(current_user)
end
def redirect_to_http
View
17 app/controllers/challenges_controller.rb
@@ -8,6 +8,7 @@
include ActionView::Helpers::NumberHelper
class ChallengesController < ApplicationController
+ before_filter :check_if_challenge_exists, :only => [:register, :submission, :submission_view_only, :cal, :preview, :show, :registrants, :results, :participant_submissions, :participant_scorecard, :scorecard, :survey]
before_filter :valid_challenge, :only => [:submission, :show, :registrants, :results, :scorecard, :register, :survey]
before_filter :must_be_signed_in, :only => [:preview, :review, :register, :watch, :register_agree_to_tos, :submission, :submission_view_only, :new_comment, :toggle_discussion_email]
before_filter :must_be_open, :only => [:submission_file_upload, :submission_url_upload]
@@ -468,21 +469,21 @@ def admin_only
end
else
redirect_to challenge_path
- end
+ end
+ end
+
+ def check_if_challenge_exists
+ render :file => "#{Rails.root}/public/challenge-not-found.html", :status => :not_found if current_challenge.nil?
+ # check for an error thrown by sfdc if they request a 'bad' challenge (e.g., /challenges/fasdaf). sfdc returns an object.
+ raise ActionController::RoutingError.new('Bad challenge request.') if !current_challenge.nil? && current_challenge.has_key?('errorCode')
end
def closed_for_registration?
@challenge_detail['Registration_End_Date__c'].nil? ? false : Time.parse(@challenge_detail['Registration_End_Date__c']).past?
end
def current_challenge
- @current_challenge ||= Challenges.find_by_id(current_access_token, params[:id])[0]
- # check for an error thrown by sfdc if they request a 'bad' challenge (e.g., /challenges/fasdaf)
- if @current_challenge.has_key?('errorCode')
- raise ActionController::RoutingError.new('Bad challenge request.')
- else
- @current_challenge
- end
+ @current_challenge ||= Challenges.find_by_id(current_access_token, params[:id])[0]
end
# most of the time the title will be the challenge name but be flexible
View
3 app/controllers/members_controller.rb
@@ -149,8 +149,7 @@ def requested_member
end
def check_if_member_exists
- @member = requested_member
- render :file => "#{Rails.root}/public/member-not-found.html", :status => :not_found if @member.nil?
+ render :file => "#{Rails.root}/public/member-not-found.html", :status => :not_found if requested_member.nil?
end
end
View
2 coverage/index.html
@@ -11461,7 +11461,7 @@
<li class="missed" data-hits="0" data-linenumber="54">
- <code class="ruby"> get(ENV['SFDC_REST_API_URL']+'/challengesearch?fields=Id,Challenge_Id__c,Name,Description__c,Top_Prize__c,Registered_Members__c,Start_Date__c,End_Date__c,Is_Open__c,License__c'+qry_orderby+qry_open+qry_category)</code>
+ <code class="ruby"> get(ENV['SFDC_REST_API_URL']+'/challengesearch?fields=Id,Challenge_Id__c,Name,Description__c,Top_Prize__c,Registered_Members__c,Start_Date__c,End_Date__c,Is_Open__c'+qry_orderby+qry_open+qry_category)</code>
</li>
<li class="never" data-hits="" data-linenumber="55">
View
BIN db/development.sqlite3
Binary file not shown.

0 comments on commit 12654e9

Please sign in to comment.