<commit_before>class CandidateControlsController < ApplicationController

	before_filter :may_create_study_subjects_required
	before_filter :valid_id_required
	before_filter :valid_case_study_subject_required

	def edit
#	TODO add potential check for reasons to reject control
#		if any found ...
#		@candidate.reject_candidate = true
#		@candidate.rejection_reason = "the reason why we think the control should be rejected."
	end

	def update
		CandidateControl.transaction do
			unless params[:candidate_control][:reject_candidate]
#	TODO what would subjects be?  just self? [self,control,mother]?
#				subjects = @candidate.create_study_subjects(@study_subject)
				@candidate.create_study_subjects(@study_subject)
#
#	add a flash[:notice] if icf_master_ids are nil (don't raise error)
#
#	do something with the icf_master_ids table as well
#		assign icf_master_id to both new child control and mother
#
			end
			# don't do it this way as opens ALL the attrs for change
			#	@candidate.update_attributes()	
			@candidate.reject_candidate = params[:candidate_control][:reject_candidate]
			@candidate.rejection_reason = params[:candidate_control][:rejection_reason]
			@candidate.save!
		end
		redirect_to case_path(@study_subject)
	rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
		flash.now[:error] = "Candidate control update failed."
		render :action => 'edit'
	end

protected

	def valid_id_required
		if !params[:id].blank? and CandidateControl.exists?(params[:id])
			@candidate = CandidateControl.find(params[:id])
		else
			access_denied("Valid candidate_control id required!", cases_path)<commit_msg>Corrected condition to create controls.<commit_after>class CandidateControlsController < ApplicationController

	before_filter :may_create_study_subjects_required
	before_filter :valid_id_required
	before_filter :valid_case_study_subject_required

	def edit
#	TODO add potential check for reasons to reject control
#		if any found ...
#		@candidate.reject_candidate = true
#		@candidate.rejection_reason = "the reason why we think the control should be rejected."
	end

	def update
		CandidateControl.transaction do
			if params[:candidate_control][:reject_candidate] == 'false'
#	TODO what would subjects be?  just self? [self,control,mother]?
#				subjects = @candidate.create_study_subjects(@study_subject)
				@candidate.create_study_subjects(@study_subject)
#
#	add a flash[:notice] if icf_master_ids are nil (don't raise error)
#
#	do something with the icf_master_ids table as well
#		assign icf_master_id to both new child control and mother
#
			end
			# don't do it this way as opens ALL the attrs for change
			#	@candidate.update_attributes()	
			@candidate.reject_candidate = params[:candidate_control][:reject_candidate]
			@candidate.rejection_reason = params[:candidate_control][:rejection_reason]
			@candidate.save!
		end
		redirect_to case_path(@study_subject)
	rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
		flash.now[:error] = "Candidate control update failed."
		render :action => 'edit'
	end

protected

	def valid_id_required
		if !params[:id].blank? and CandidateControl.exists?(params[:id])
			@candidate = CandidateControl.find(params[:id])
		else
			access_denied("Valid candidate_control id required!", cases_path)
{'fraction_non_alphanumeric': 0.08533252353477072, 'fraction_numerical': 0.0, 'mean_word_length': 5.777777777777778, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '668176', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1006, 'n_words': 264}