Error Catching, and Implementing Notes

Today we repair what we broke last time.

This entry is the most boring of all, as all it does is fix errors and “features” that were introduced (intentionally or no) in the prior work. At the end, the student experiment integrates quesiton lists and notes, but doesn’t actually save the results.

Try to go to the manage_question_lists controller and, at least with how I’ve entered data, you get this unfriendly message

ActiveRecord::RecordNotFound in Manage_question_lists#index

Showing app/views/manage_question_lists/list.rhtml where line #32 raised:

Couldn’t find QuestionList without an ID

Extracted source (around line #32)


32: <% question_list = QuestionList.find(question_list_condition.question_list_id) %>

First, it’s easy to see that this is a bad design. It makes catching errors hard, as we see right now. So in question_list.rb, add a new function

def self.find_by_id(id)
found_object = find(id)
@to_return = found_object
logger.error("Error: No record found for id " + id.to_s + " generated by question_list.rb:find_by_id")

The error reveals that there is a QuestionListID (no. 4, in my case) being called, in spite of its presense in QuestionListConditions. Now we’ll do some begin/rescue/end code in _list.rhtml to make it error out prettier (wouldn’t want this error while showing it off someday!) while next finding out what causes this problem in the first place.

The code to do the first part is pretty simple. Also We’ll check to make sure that the question_list exists — so now we have a double-layer of code!

<% if question_list %>
<% begin %>
<td><%= h %></td>
<td><%= h %></td>
<td><%= text_field :question_ordering,, :value => question_list_condition.ordering, :size=>3 %></td>
<td><%= h question_list.description %></td>
<td><%= link_to ‘Show’, :action => ‘show’, :id => question_list %></td>
<td><%= link_to ‘Edit’, :action => ‘edit’, :id => question_list %></td>
<td><%= link_to ‘Destroy’, { :action => ‘destroy’, :id => question_list }, :confirm => ‘Are you sure?’, :method => :post %></td>
<% rescue %>
<br />Error encountered</td>
<% end %>
<% else %>
<tr /><td>QL <%= %> does not exist </td></tr>
<% end %>

(That extra td is there after Error encountered because the problem presumable happened while in a table cell)

Presumably this problem is caused by a question_list that existed but was deleted. And indeed, the question_list id tag appears in two places: in question_lists and question_list_conditions. Therefore, whenever a question_list is destroyed, the question_list_conditions with that question_list_id should be destroyed as well.

in models,question_list_condition.rb, add the following function

def self.destroy_by_question_list_id(question_list_id)
question_list_conditions = find(:all,$conditions=>{:question_list_id => question_list_id})
for question_list_condition in question_list_conditions

And update controllers/manage_question_lists_controller.rb to have

def destroy
question_list_id = params[:id]
QuestionListConditions.find(:all, :conditions=>{:question_list_id =>question_list_id}).destroy
flash[:notice] = ‘QuestionList was successfully deleted.’
flash[:notice] = ‘QuestionList was not successfully deleted.’
redirect_to :action => ‘list’

Next to fix: manage_question_options for a similar problem. Update views/manage_question_options/list.rhtml to read as follows:

<h1>Listing question_options</h1>

<th>Question ID</th>
<th>Question Text</th>
<th>Display Text</th>
<% for question_option in @question_options %>
<% begin %>
<td><%= %></td>
<td><%= question_option.question_id %></td>
<td><%= Question.find_name_by_id(question_option.question_id) %></td>
<td><%= question_option.option_id %></td>
<td><%= question_option.display_text %></td>
<% rescue %>
<br />QuestionOption no. <%= %> generated an error</td>
<% end %>
<td><%= link_to ‘Show’, :action => ‘show’, :id => question_option %></td>
<td><%= link_to ‘Edit’, :action => ‘edit’, :id => question_option %></td>
<td><%= link_to ‘Destroy’, { :action => ‘destroy’, :id => question_option }, :confirm => ‘Are you sure?’, :method => :post %></td>
<% end %>

<%= link_to ‘Previous page’, { :page => @question_option_pages.current.previous } if @question_option_pages.current.previous %>
<%= link_to ‘Next page’, { :page => } if %>

<br />

<%= link_to ‘New question_option’, :action => ‘new’ %>

Now that this works, I went through and deleted all the questions and question_lists stuff. Now to re-create. First, after a question_list is created, send the user to the create new question screen with this line:

redirect_to :controller => ‘manage_questions’, :action => ‘new’

in manage_question_lists_controll.rb:create()

Now that’s done, I went through and created some appropiate question_lists and questions. Finally, we need to finish up the student controller to allow experiments to be taken.

Add the following code to the _question_types.rhtml partial under the students view

<% if question.type_id == QuestionType::NOTES_MATRIX or question.type_id == QuestionType::NOTES_LINEAR %>

<% @notes_fields = NotesField.find_by_condition(@student.condition_id) %>
<% @notes_records = NotesRecord.find_by_condition(@student.condition_id) %>
<%= render :partial => "notes_view" %>
<% end %>

The concluding portion of the students_controller.rb:run_experiment function should read

flash[:notice] = ‘Finished experiment.’
redirect_to :action => ‘index’


And now we can talk through the notes experiment!

Of course, it doesn’t save, but that’s a project for another time…

Cognitive Development, Part VII: Memory

The seventh chapter of Flavell, Miller, & Miller’s Cognitive Development, entitled “Memory,” has the broadest implications yet. From broad topics like intelligence and genetics, to foreshadowing an experiment I plan to conduct in the next year, this chapter was fascinating.

I found it fascinating that later intelligence can be predicted from habituation speed (Bornstein & Sigman, 1986). I wonder if this is also true of adults? I also wonder what the heritability of this behavior is, especially as compared to the heritability of general intelligence, where respectable estimates range from .86 (Posthuma, 2002) to half that figure (Devlin, Daniels, & Roader, 1997)?

Still, Flavell, Miller, & Miller’s blindness to ancestry as an independent variable, even in the discussion, is aggravating. Their non-view of group-level genetic diversity, reminiscent of nothing so much as the Victorians’ non-view of sex, continues with considering culture but not race as factors in difference between Korean and American mother-to-infant speech (Muellen & Yi, 1995) or differences in acquiring number counting between Chinese and American children (Geary, Fan, Bow-Thomas, & Siegler, 1993).

The blinders when it comes to race are all the more frustrating, because when it comes to intelligence or behavior the authors are much less absolutist. For instance, reporting the finding that “Children of repetitive mothers tend to recall less and have less organized memories” the authors conclude that “the mother’s style is ‘pass on’ to the child” (242, abstracted from Reese, Haden, & Fivush, 1993). Indeed, that is exactly what the findings show. Is the behavior passed on environmentally, genetically, or as an interaction? Who knows? That is the proper way to do science. (In the context of the above, it would be interesting to see if beginning of numeracy or even finger-tapping rates (Guttentag, 1984) are heritable. I would assume they were.)

Also interesting was the section on eyewitness testimony. There’s good reason to be skeptical of child testimony (Sagan, 1997). Indeed, one “survivor” even believed he had been eaten alive (Goodman, Aman, & Hirschman, 1987)! Likewise, children’s increased likelihood to change their answers under repeated questioning (Cassel, Roebers, & Bjorklund, 1996) acalls into question how much of standard procedure can even be used with question. One wonders if the fact that “children with higher theory-of-mind scores were less likely to be misled” implies that childhood reliability varies with intelligence. In other words, does the link between childhood abuse and cognitive issues like short-term memory loss (Bremner, et al., 1995) go both ways?

I was happy where the chapter noted that learning skills takes time because performing then can be “rather effortful, challenging, and attention demanding as an act in itself for young children” (251, summarizing Guttentag, 1997). This emphasizes that skills are just narrow domains that operate under the same rule as creativity anywhere else: that is, through time and purposeful practice (Csikszentmihalyi, 1996; Ross, 2006). Considering the children are indeed “universal novices” (257, quoting Brown & DeLoache, 1978), the purpose of childhood education should be to teach expertise in those skills that do not come naturally and that they actually need. Instead, too many schools focus on “comprehension,” building up loose semantic nets that do not help much. Expertise counts for more than learning-speed (Schneider et al, 1989), that is intelligence, so schools should focus on building that .

To end this paper, I enjoyed the section on megacognitive experiences that began on page 264. In my own research, I’ve enjoyed discovering the limits of metaknowledge among students, particularly knowledge of their own behaviors. With regards to a wider theme of unexpectedly competent babies and unexpectedly incompetent late adolescents, it is interesting that even two year olds experience “feelings of knowing (DeLoache & Brown, 1984) about facts in the past, while in my studies I found 19 year olds not knowing what they will do in the future.

Cognitive Development, a tdaxp series
1. Introduction
2. Infant Perception
3. Infant Cognition
4. Representation and Concepts
5. Reasoning and Problem Solving
6. Social Cognition
7. Memory
8. Language
9. Questions and Problems
10. Bibliography