CSC/ECE 517 Fall 2014/oss E1502 wwj: Difference between revisions
Jump to navigation
Jump to search
Line 53: | Line 53: | ||
Change from "for question in @questionnaire.questions" to "@questionnaire.questions.each do |question|"<br> | Change from "for question in @questionnaire.questions" to "@questionnaire.questions.each do |question|"<br> | ||
Before | Before | ||
<pre> | |||
# Remove a given questionnaire | # Remove a given questionnaire | ||
def delete | def delete | ||
Line 61: | Line 61: | ||
begin | begin | ||
name = @questionnaire.name | name = @questionnaire.name | ||
<b> | |||
for question in @questionnaire.questions | for question in @questionnaire.questions</b> | ||
current_q_type = QuestionType.find_by_question_id(question.id) | current_q_type = QuestionType.find_by_question_id(question.id) | ||
unless current_q_type.nil? | unless current_q_type.nil? | ||
Line 81: | Line 81: | ||
redirect_to :action => 'list', :controller => 'tree_display' | redirect_to :action => 'list', :controller => 'tree_display' | ||
end | end | ||
</pre> | |||
After | After | ||
<pre> | <pre> | ||
Line 91: | Line 91: | ||
begin | begin | ||
name = @questionnaire.name | name = @questionnaire.name | ||
@questionnaire.questions.each do |question| | @questionnaire.questions.each do |question| | ||
current_q_type = QuestionType.find_by_question_id(question.id) | current_q_type = QuestionType.find_by_question_id(question.id) | ||
if current_q_type | if current_q_type |
Revision as of 02:46, 21 March 2015
E1502: Questionnaire Controller Refactoring
red writing
Introduction to Expertiza
Project Description
What it does:
Used on the admin side of Expertiza for creating/ editing questionnaires (rubrics, surveys and quizzes). It helps in add/removing questions, options, etc for a questionnaire.
Other classes involved:
What needs to be done:
What We Have Done
Method Refactoring
Method Name | Changes Made | Reason For Change |
---|---|---|
copy | Extracted the content of this method as copy_questionnaires method and put it in questionnaire.rb | The content of this method is about operations on the database (coping a questionnaire), it is better to put it in the model |
valid_quiz | Moved this method to quiz_questionnaire.rb | This method is about validation of the quiz, it shouldn't appear in the controller |
export | Moved this method to questionnaire.rb | This method exports the questionnaires as csv file, it should't appear in the controller |
import | Moved this method to questionnaire.rb | This method imports the questionnaires from csv file, it should't appear in the controller |
clone_questionnaire_details | Deleted this method due to the duplication | Substituted by copy_questionnaires method in questionnaire.rb |
Format Refactoring
Case 1:
Change from "for question in @questionnaire.questions" to "@questionnaire.questions.each do |question|"
Before
# Remove a given questionnaire def delete @questionnaire = Questionnaire.find(params[:id]) if @questionnaire begin name = @questionnaire.name <b> for question in @questionnaire.questions</b> current_q_type = QuestionType.find_by_question_id(question.id) unless current_q_type.nil? current_q_type.delete end end @questionnaire.assignments.each{ | assignment | raise "The assignment #{assignment.name} uses this questionnaire. Do you want to <A href='../assignment/delete/#{assignment.id}'>delete</A> the assignment?" } @questionnaire.destroy undo_link("Questionnaire \"#{name}\" has been deleted successfully. ") rescue flash[:error] = $! end end redirect_to :action => 'list', :controller => 'tree_display' end
After
# Remove a given questionnaire def delete @questionnaire = Questionnaire.find(params[:id]) if @questionnaire begin name = @questionnaire.name @questionnaire.questions.each do |question| current_q_type = QuestionType.find_by_question_id(question.id) if current_q_type current_q_type.delete end end @questionnaire.assignments.each{ | assignment | raise "The assignment #{assignment.name} uses this questionnaire. Do you want to <A href='../assignment/delete/#{assignment.id}'>delete</A> the assignment?" } @questionnaire.destroy undo_link("Questionnaire \"#{name}\" has been deleted successfully. ") rescue flash[:error] = $! end end redirect_to :action => 'list', :controller => 'tree_display' end