Today (and last night, actually) the rough draft, I guess you could call it the first beta or so, of the system works. From beginning to end, from survey items, notes, and output, it’s all there. A lot of things were changed in the final stretch. Below the fold are some of them.
The notes today are scattered, but so was the accomplishment: a functional system.
app/views/output/index.rhtml
<html><head><title>Output for Notes on Rails</title></head>
<body>
<table border=1>
<tr><td colspan="6"><h1>Output Listing</h2></td></tr>
<% for experiment in @experiments %>
<tr><td colspan="6"> <h2>Experiment <i><%= experiment.name %></i></h2></td></tr>
<% for condition in Condition.find_conditions_array(experiment.id) %>
<tr><td colspan="6"> <h3>Condition <i><%= condition.name %></i></h3></td></tr>
<tr>
<td><b>Survey Response ID</b></td>
<td><i>QuestionList</i></td>
<td>Question</td>
<td><b>Field (i/a)</b></td>
<td><i>Record (i/a)</i></td>
<td>Survey Text</td>
</tr>
<% for student in Student.find_students(condition.id) %>
<tr><td colspan="6"> <h4>Student <i><%= student.name %></i> (<%= student.id %>)</h3></td></tr>
<% for survey_response in SurveyResponse.find(:all, :conditions => ['student_id = ?',student.id]) %>
<tr>
<td><%= survey_response.id %></td>
<td><%= QuestionList.find_name_by_id(survey_response.question_list_id) %>
<% question = Question.find(survey_response.question_id) %>
</td>
<td><%= question.name %></td>
<td>
<% if survey_response.field_identifier %>
<br /><%= NotesField.find_name_by_id(survey_response.field_identifier) %>
<% end %>
</td>
<td><%
if question.type_id == QuestionType::NOTES_MATRIX || question.type_id == QuestionType::NOTES_LINEAR
record_name = NotesRecord.find_name_by_id(survey_response.record_identifier)
elsif question.type_id == QuestionType::CHECKBOX || question.type_id = QuestionType::SELECTION || question.type_id = QuestionType::RADIO
#record_name = "Find display text with QuID = " + question.id.to_s + " and OptID = " + survey_response.record_identifier.to_s
record_name = QuestionOption.find_display_text_by_question_id_option_id(question.id,survey_response.record_identifier)
else
record_name = ""
end
%>
<%= record_name %>
</td>
<td><%= survey_response.survey_text %></td>
</tr>
<% end %>
<% end %>
<% end %>
<% end%>
</table>
</body>
</html>
app/views/students/_notes_view.rhtml
<table border="1">
<tr>
<td> </td>
<% for notes_record in @notes_records %>
<td><%= h(notes_record.name) %></td>
<% end %>
</tr>
<% for notes_field in @notes_fields %>
<tr>
<td><%= notes_field.name %></td>
<% for notes_record in @notes_records %>
<td><%= text_area :survey_text, notes_field.id.to_s + "_" + notes_record.id.to_s, :cols => 20, :rows => 8 %></td>
<% end %>
</tr>
<% end %>
</table>
the run_experiment function of students_controller.rb:
def run_experiment
@student = Student.find(session[:student])
unless @student.condition_id
@student.condition_id = params[:student][:condition_id]
@student.save
end
## Saving data goes here
@questions = Question.find_by_question_list_id(@student.current_question_list)
if (@questions)
for question in @questions
question = Question.find(question.id)
if (question.type_id == QuestionType::NOTES_MATRIX || question.type_id == QuestionType::NOTES_LINEAR)
@notes_fields = NotesField.find_by_condition(@student.condition_id)
@notes_records = NotesRecord.find_by_condition(@student.condition_id)
for note_field in @notes_fields
for note_record in @notes_records
@survey_response = SurveyResponse.new(
:student_id => @student.id,
:question_list_id => @student.current_question_list,
:question_id => question.id,
:field_identifier => note_field.id,
:record_identifier => note_record.id,
:survey_text => params[:survey_text][note_field.id.to_s + "_" + note_record.id.to_s]
)
@survey_response.save()
end
end
elsif question.type_id == QuestionType::CHECKBOX
checkboxes = params['question_' + question.id.to_s]
for checkbox in checkboxes
checkbox_option = checkbox[0]
checkbox_value = checkbox[1]
if checkbox_value == "1"
@survey_response = SurveyResponse.new(
:student_id => @student.id,
:question_list_id => @student.current_question_list,
:question_id => question.id,
:record_identifier => checkbox_option,
:survey_text => 1
)
@survey_response.save
end
end
else
if question_text = params[:question]
question_text = params[:question][question.id.to_s]
@survey_response = SurveyResponse.new(
:student_id => @student.id,
:question_list_id => @student.current_question_list,
:question_id => question.id,
:survey_text => question_text
)
@survey_response.save()
flash[:notice] = ’0D. for ‘ + question_text
end
end
end
end
## stop saving data here
@next_question_list = Student.find_next_question_list(@student.condition_id,@student.current_ordering)
if @next_question_list
@student.current_question_list = @next_question_list.question_list_id
@student.current_ordering = @next_question_list.ordering
@student.save
@questions = Question.find_by_question_list_id(@student.current_question_list)
else
flash[:notice] = ‘Finished experiment.’
redirect_to :action => ‘index’
end"
end
First, the little hidden field in _question_types.rhtml should now read:
<%= hidden_field_tag "question[" + question.id.to_s + "]" %></i>
in _question_types.rhtml
<i> <% if question.type_id == QuestionType::CHECKBOX %>
<% @options = Question.find_question_options_array(question.id) %>
<% for option in @options %>
<%= check_box(question.id,option.option_id) %><%= option.display_text %>
<% end %>
<% end %>
Hmmm — we also need to update manage_question_list/create. The solution here is trivially easy. In manage_question_lists/_form.rhtml, change the foreach experiment line to read
<% for experiment in Experiment.find(:all) %>
Also, rename NotesField.name_from_id and NotesRecord.name_from id to find_name_by_id. Consistency, consistency, consistency!