Against The Racial Gap

It goes without saying that the Iraq War, as it has been fought since the “occupation” was begun, has been a disaster. Thousands of American lives have been lost in the persuit transition the Sunni Arab regime of Iraq into a liberal mandarin democracy. In terms of American lives lost, the Iraq War has been the greatest foreign policy disaster since 9/11… if not the Vietnam War. The Iraq War, 2004 till now, is the greatest stain on George Bush’s legacy.

The Case Against George Bush

The decisions fo Chief Justice John Roberts and Associate Justice Samuel Alito, alone, make up for Bush’s errors in other places.

The goal of our time is “shrinking the gap,” saving from lawlessness that portion of humanity stuck in tribal warfare and murderous violence. An important part of thsi is shrinking the Afro-Islamic Gap, using everything from a military-industrial complex to mass humiliation to save lives and make the world a better place.

However, there is a gap in America too. Most egregiously, tens of thousands of infants are put to death every year in abortions. In April, the Supreme Court took the first steps of ending recreational infanticide within the United States.

Now, more great news: the Supreme Court has sharply limited the ability of school districts to use race as a factor in school assignments.


A Ghettoized Community

It’s impossible to talk about race in America without describing the population known as “black,” so here goes. American blacks generally form a hyrbid population, with about a 20% ingression of caucasoid genetics into an otherwise 80% negroid population. (By comparison, Tiger Woods is 25% negroid while Barack Obama is 50%. Turkish “Turks” are about 20% Turkik and 80% Anatolian/”Greek”.)

An old and regrettable policy in the United States has been to regard as “black” anyone with any negroid blood, and to then use this designation to determine public services. (A variation on this are is to regard anyone with any non-caucausoid blood as a “minority.”) Whatever the motives of the racialists who created and enforced the plan, the effect has been the same: to minimize the exposure of “blacks” to the market system and instead enforced a ghettoized economy of rents and duties on them.

There is a reason that “African Americans” (those “blacks” whose ancestors were slaves in the American South) perform poorly as a population, and it is neither their genes nor their past as slaves (they share both with their higher-performing Afro-Carribiean fellow citizens). Rather, it is the history of race-based separation that they have faced in America, from the end of reconstruction to now, rather devised (largely) by American Democrats who felt that blacks were unable to compete with whites before Brown v. Board… to (largely) American Democrats who felt that blacks were unable to compete with whites after Brown v. Board.

The Supreme Court’s decision today is a powerful blow to a racialist America, and a large step forward in the integration of all Americans into the Core.

Thank you Chief Justice Roberts, Justice Alito, Justice Kennedy,Justice Scalia, and Justice Thomas.

Thank you, President Bush.

Linwood Wilson Out

Linwood Wilson, one of the Durham County thugs who helped Michael Byron Nifong and his co-conspirators (Crystal Gail Mangum, Jessee Jackson, the Group of 88, etc) try to get some youths raped in prison, has lost his job.

Fortunately, the villians are now stabbing each other in the back. Durham-in-Wonderland has video and text of Nifong criticizing Wilson.

For those new to the scandal, an enjoyable recap is available onYouTube.

Creating a Basic Question-List Interface

The presentaiton was a hit. The next step is to make the “take the experiment” feature less fakey, by incorporating pretests and posttests. My inspiration for how to do this comes from MediaLab, which I worked with previously.

Every Question will belong to a QuestionList. Every QuestionList can belong to any number of conditions. There will also be a model that ties QuestionLists into Conditions and one that ties QuestionOptions into Questions. The table schemes are something like :


Question
-ID
-Name
-Display
-Type
-ListID

-QuestionList
-ID
-Name
-Description

QuestionOptions
-ID
-QuestionID
-Name
-OptionText

QuestionListConditions
-ID
-ConditionID
-QuestionListID

ruby script/generate model question
ruby script/generate model question_list
ruby script/generate model question_option
ruby script/generate model question_list_condition

Then generate the appropriate models

Now to through the migrations, added fields as necessary

015_create_questions.rb

class CreateQuestions < ActiveRecord::Migration
def self.up
create_table :questions do |t|
t.column :name, :string
t.column :display, :text
t.column :type, :integer
t.column :list_id, :integer
end
end

def self.down
drop_table :questions
end
end

016_create_question_lists.rb

class CreateQuestionLists < ActiveRecord::Migration
def self.up
create_table :question_lists do |t|
t.column :name, :string
t.column :description, :text
end
end

def self.down
drop_table :question_lists
end
end

017_create_question_options.rb

class CreateQuestionOptions < ActiveRecord::Migration
def self.up
create_table :question_options do |t|
t.column :question_id, :integer
t.column :name, :string
t.column :optiontext, :text
end
end

def self.down
drop_table :question_options
end
end

018_create_question_list_conditions.rb

class CreateQuestionListConditions < ActiveRecord::Migration
def self.up
create_table :question_list_conditions do |t|
t.column :condition_id, :integer
t.column :question_list_id, :integer
end
end

def self.down
drop_table :question_list_conditions
end
end

Then rake db:migrate

Next, we’ll create the controller and the scaffold for questions and question_lists, as was done on day one.

ruby script/generate controller manage_questions
ruby script/generate controller manage_question_lists

Then generate the static scaffolds, like in day two.

ruby script/generate scaffold question manage_questions
ruby script/generate scaffold question_list manage_question_lists

Now create controllers for question_options and question_list_conditions. We are actually creating two classes of controllers here — the basic steps of setting up an experiment and the more mundane database-interface controllers. But more on that in a bit. For now:

ruby script/generate controller manage_question_options
ruby script/generate controller manage_question_list_conditions
ruby script/generate scaffold question_option manage_question_options
ruby script/generate scaffold question_list_condition manage_question_list_conditions

Now add the interface code as done two days ago to our four new controllers:

layout “notesonrails”

And modify /views/layouts/notesonrails.html as appriate. The goal is to provide access to every controller while differentiating controllers designed for use, for debugging, for output, and for the experiment itself:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= controller.controller_name %>: <%= controller.action_name %></title>
<%= stylesheet_link_tag ‘scaffold’ %>
</head>
<body>

<p style="color: green"><%= flash[:notice] %></p>
<h1>Notes on Rails Admin Interface</h1>
<div id="menu_area">
<p>Create an Experiment:
<%= link_to ( "Experiments",
:controller => :manage_experiments, :action => :index ) %>,
<%= link_to ( "Conditions",
:controller => :manage_conditions,
:action => :index ) %>,
<%= link_to ( "Question Lists",
:controller => :manage_question_lists ) %>,
<%= link_to ( "Questions",
:controller => :manage_questions ) %>,
<%= link_to ( "Fields",
:controller => :manage_notes_fields ) %>,
<%= link_to ( "Records",
:controller => :manage_notes_records ) %>,
</p>

<p>Other Features:
<%= link_to ( "Notes",
:controller => :manage_notes ) %>,
<%= link_to ( "Students",
:controller => :manage_students ) %>,
<%= link_to ( "QuestionList Conditions",
:controller => :manage_question_list_conditions ) %>,
<%= link_to ( "Question Options",
:controller => :manage_question_options ) %> |
<%= link_to ( "Output",
:controller => :output ) %> |
<b><%= link_to ( "Take an Experiment!",
:controller => :students ) %></b></p>
</div>
<%= yield %>

</body>
</html>

Next up, alter the manage_question_lists controller so that one may pick several conditions for the question list to b belong too

in new(), add the line “@experiments = Experiment.find(:all)” and in _form.rhtml

Now let’s add some check boxes to the manage_question_lists controller so that we can associate it with our conditions

Firs,t let’s add some methods on question_list_condition.rb controller:

class QuestionListCondition < ActiveRecord::Base
def self.destroy_by_condition_id_question_list_id(condition_id,question_list_id)
to_destroy = find_by_condition_id_question_list_id(condition_id,question_list_id)

to_destroy.destroy if to_destroy
end

def self.add_by_condition_id_question_list_id(condition_id,question_list_id)
to_add = find_by_condition_id_question_list_id(condition_id,question_list_id)

if to_add
return to_add
else
to_add = QuestionListCondition.new(
:condition_id => condition_id,
:question_list_id => question_list_id
)
to_add.save
return to_add
end
end

def self.find_by_condition_id_question_list_id(condition_id,question_list_id)

to_return = find(
:first,
:conditions => {
:condition_id => condition_id,
:question_list_id => question_list_id
}
)

to_return
end
end

update four functions in manage_question_lists_controller.rb:

def new
@question_list = QuestionList.new
@experiments = Experiment.find(:all)
end

def create
@question_list = QuestionList.new(params[:question_list])
@result_of_save = @question_list.save

@question_list_conditions = params[:selected_condition]
for question_list_condition in @question_list_conditions
@question_list_condition_id = question_list_condition[0].to_i
@question_list_condition_show = question_list_condition[1].to_i
if @question_list_condition_show == 1
QuestionListCondition.add_by_condition_id_question_list_id(@question_list_condition_id,@question_list.id)
else
QuestionListCondition.destroy_by_condition_id_question_list_id(@question_list_condition_id,@question_list.id)
end
end

if @result_of_save
flash[:notice] = ‘QuestionList was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end

end

def edit
@question_list = QuestionList.find(params[:id])
@experiments = Experiment.find(:all)

end

def update
@question_list = QuestionList.find(params[:id])

@question_list_conditions = params[:selected_condition]
for question_list_condition in @question_list_conditions
@question_list_condition_id = question_list_condition[0].to_i
@question_list_condition_show = question_list_condition[1].to_i
if @question_list_condition_show == 1
QuestionListCondition.add_by_condition_id_question_list_id(@question_list_condition_id,@question_list.id)
else
QuestionListCondition.destroy_by_condition_id_question_list_id(@question_list_condition_id,@question_list.id)
end
end

if @question_list.update_attributes(params[:question_list])
flash[:notice] = ‘QuestionList was successfully updated.’
redirect_to :action => ‘show’, :id => @question_list
else
render :action => ‘edit’
end
end</i>

and then the _form.rhtml partial:

<i><%= error_messages_for ‘question_list’ %>

<!–[form:question_list]–>
<p><label for="question_list_name">Name</label><br/>
<%= text_field ‘question_list’, ‘name’ %></p>

<p><label for="question_list_description">Description</label><br/>
<%= text_area ‘question_list’, ‘description’, :rows=>4 %></p>

<p><label for="question_list_conditions">Conditions</label><br />
<% for experiment in @experiments %>
<p><%= experiment.name %>
<% @conditions = Condition.find_conditions_array(experiment.id) %>
<% for condition in @conditions %>
<br /><%= check_box :selected_condition, condition.id %>
<%= condition.name %>
<% end %></p>
<% end %>

<!–[eoform:question_list]–>

Excellent. To finish up today, just edit the administrative question_list_condition view, as right now it’s blank because it’s looking for content_columns, of which it has none:

—-

We won’t do everything for this scaffolding, but we will fix this list and make some code more portable.

In experiment.rb, change find_name_by_id to

def self.find_name_by_id(selected_id)
found_object = find(selected_id)
@to_return = found_object.name
end

now, copy and paste the same code into question_list.rb, while also adding

validates_presence_of :name, :description

to the top

Last, change list.rhtml to:

<h1>Listing question_list_conditions</h1>

<table>
<tr>
<th>ID</th>
<th>Condition</th>
<th>Question List</th>
</tr>
<% for question_list_condition in @question_list_conditions %>
<tr>
<td><%= question_list_condition.id %></td>
<td><%= Condition.find_name_by_id(question_list_condition.condition_id) %></td>
<td><%= QuestionList.find_name_by_id(question_list_condition.question_list_id) %></td>
</tr>
<% end %>
</table>

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

<br />

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

Tomorrow: adding questions!

Christian Intellectual Death Squads

As a Catholic, I view the Protestant churches as essentially loyalty militias, forces that by-and-large assist the Christian correlation-of-forces but nonetheless escape any accountability from the earthly hierarchy. Thus, the Lutheran Church (Missouri Synod) is to the Holy See as the Badr Brigades are to the Republic of Iraq.

However, in this model there should be another category — death squads — of those who might be classified as loyalty militia except that the blowback from them is roughly as bad as the good they do. Death squads differ from other actors in that they are ideologically motivated and focus on the same concepts as the larger insurgency.

alpha_chi_ro_omega_md

The Seen and the Unseen

The most visible Christian ideological death squad is Islam, for obvious reasons. However, evangelical secularism or Ultracavlisnism, may form a Christian intellectual death-squad as well. Unqualified Reservations has more, courtesy of gnxp:

The “ultracalvinist hypothesis” is the proposition that the present-day belief system commonly called “progressive,” “multiculturalist,” “universalist,” “liberal,” “politically correct,” etc, is actually best considered as a sect of Christianity.

Specifically, ultracalvinism (which I have also described here and here) is the primary surviving descendant of the American mainline Protestant tradition, which has been the dominant belief system of the United States since its founding. It should be no surprise that it continues in this role, or that since the US’s victory in the last planetary war it has spread worldwide.

In fact, they are so unusual that most people don’t see ultracalvinism as Christian at all. For example, on the theological side, ultracalvinism is best known as Unitarian Universalism. (It’s an interesting exercise to try to find any conflicts between UUism and “political correctness.”) Ultracalvinists are perfectly free to be atheists, or believe in any God or gods – as long as they don’t adhere to any revealed tradition, which would make them “fundamentalists.” In general, ultracalvinists oppose revelation and consider their beliefs to be pure products of reason. And perhaps they are right in this – but I feel the claim should at least be investigated.

And when we look at the real-world beliefs of ultracalvinists, we see that ultracalvinism is anything but content-free. By my count, the ultracalvinist creed has four main points:

First, ultracalvinists believe in the universal brotherhood of man. As an Ideal (an undefined universal) this might be called Equality. (“All men and women are born equal.”) If we wanted to attach an “ism” to this, we could call it fraternalism.

Second, ultracalvinists believe in the futility of violence. The corresponding ideal is of course Peace. (“Violence only causes more violence.”) This is well-known as pacifism.

Third, ultracalvinists believe in the fair distribution of goods. The ideal is Social Justice, which is a fine name as long as we remember that it has nothing to do with justice in the dictionary sense of the word, that is, the accurate application of the law. (“From each according to his abilities, to each according to his needs.”) To avoid hot-button words, we will ride on a name and call this belief Rawlsianism.

Fourth, ultracalvinists believe in the managed society. The ideal is Community, and a community by definition is led by benevolent experts, or public servants. (“Public servants should be professional and socially responsible.”) After their counterparts east of the Himalaya, we can call this belief mandarism.

In fact, the four points are very common and easily recognizable tenets of Protestant Christianity, specifically in its Calvinist or Puritan strain. You can find them all over the place in the New Testament, and any subject of Oliver Cromwell’s saintly republic would have recognized them instantly. Rawlsianism is definitely the last of the four to develop, but even it is very common in the 17th century, when its adherents were known as Diggers – a name that, not surprisingly, was later reused. Ultracalvinism fits quite neatly in the English Dissenter and low church tradition. (Note the blatant POV of the latter page, with loaded words like “reform,” a good indication that Wikipedians incline to ultracalvinism.)

Ultracalvinism’s camouflage mechanism is easy to understand. If you are an ultracalvinist, you must dispute the claim that the four points are actually Christian, because you believe in them, and you believe they are justified by reason rather than faith. Therefore they are universal and no one can doubt them, whether Christian, Muslim or Jew.

What are the adaptive advantages of crypto-Christianity? Why did those Unitarians, or even “scientific socialists,” who downplayed their Christian roots, outcompete their peers?

Well, I think it’s pretty obvious, really. The combination of electoral democracy and “separation of church and state” is an almost perfect recipe for crypto-Christianity.

As I’ve said before, separation of church and state is a narrow-spectrum antibiotic. What you really need is separation of information and security. If you have a rule that says the state cannot be taken over by a church, a constant danger in any democracy for obvious reasons, the obvious mutation to circumvent this defense is for the church to find some plausible way of denying that it’s a church. Dropping theology is a no-brainer. Game over, you lose, and it serves you right for vaccinating against a nonfunctional surface protein.

Several intellegent and well spoken atheists, including Adam of The Metropolis Times, frequent this blog. I would love to hear their opinion

Making the Interface Pretty

This post started out as something different. But after an incredible amount of work (that required purchasing We Can Replace You by “The Cells” in a desperate attempt to frighten the framework into submission), the solution ended up being embarrassingly easy (it is rails, after all). Thanks to a fellow Husker for helping me see hte way forward, and Chris Hardy (as always) for his html special character converter


A Firefoxy Interface

add the following line to AdminController, ManageConditionsController, ManageExperimentsController, ManageNotesController, ManageNotesFieldsController, ManageNotesRecordsController, ManageStudentsController, OutputController, and StudentsController right after the “class” line at the top:


layout “notesonrails”

Then in app/views/layout, create notesonrails.rhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= controller.controller_name %>: <%= controller.action_name %></title>
<%= stylesheet_link_tag ‘scaffold’ %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<h1>Notes on Rails Admin Interface</h1>
<div id="menu_area">
<%= link_to ( "Manage Experiments",
:controller => :manage_experiments, :action => :index ) %>
<%= ink_to ( "Manage Conditions",
:controller => :manage_conditions,
:action => :index ) %>,
<%= link_to ( "Manage Notes Fields",
:controller => :manage_notes_fields ) %>,
<%= link_to ( "Manage Notes Records",
:controller => :manage_notes_records ) %>,
<%= link_to ( "Manage Students",
:controller => :manage_students ) %>,
<%= link_to ( "Manage Notes",
:controller => :manage_notes ) %>,
<%= link_to ( "Output",
:controller => :output ) %> |
<b><%= link_to ( "Take a Survey!",
:controller => :students ) %></b>.
</div>
<%= yield %>
</body>
</html>

Now let’s go through the scaffolds and update some things

views/manage_conditions/list.rhtml should be

<h1>Listing conditions</h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Experiment</th>
</tr>
<% for condition in @conditions %>
<tr>
<td><%= condition.id %></td>
<td><%= condition.name %></td>
<td><%= condition.description %></td>
<td><%= Experiment.find_name_by_id(condition.experiment_id) %></td>
<td><%= link_to ‘Show’, :action => ‘show’, :id => condition %>
</td>
<td><%= link_to ‘Edit’, :action => ‘edit’, :id => condition %></td>
<td><%= link_to ‘Destroy’, { :action => ‘destroy’, :id => condition }, :confirm => ‘Are you sure?’, :method => :post %></td>
</tr>
</p></td></tr>
<% end %>
</table>
<br />
<%= link_to ‘New condition’, :action => ‘new’ %>

add to experiment.rb:

def self.find_name_by_id(selected_experiment_id)
experiment = find(selected_experiment_id)
@condition_condition = experiment.name
end

In conditions.rb, add

def self.find_name_by_id(selected_argument_id)
condition = find(selected_argument_id)
@to_return = condition.name
end

def self.find_experiment_id_by_id(selected_argument_id)
condition = find(selected_argument_id)
@to_return = condition.experiment_id
end

Change app/views/manage_notes_fields/list.rhtml to

<h1>Listing notes_fields</h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Condition</th>
<th>Experiment</th>
</tr>
<% for notes_field in @notes_fields %>
<tr>
<td><%= notes_field.id %></td>
<td><%= notes_field.name %></td>
<td><%= notes_field.description %></td>
<td><%= Condition.find_name_by_id(notes_field.condition_id) %></td>
<td><%= Experiment.find_name_by_id(Condition.find_experiment_id_by_id(notes_field.condition_id)) %></td>
<td><%= link_to ‘Show’, :action => ‘show’, :id => notes_field %></td>
<td><%= link_to ‘Edit’, :action => ‘edit’, :id => notes_field %></td>
<td><%= link_to ‘Destroy’, { :action => ‘destroy’, :id => notes_field }, :confirm => ‘Are you sure?’, :method => :post %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to ‘New notes_field’, :action => ‘new’ %>

update the following two in manage_notes_fields_controller.rb:

def list
@notes_fields = NotesField.find(:all)
end

def show
@notes_field = NotesField.find(params[:id])

@notes_field_name = @notes_field[‘name’]
@notes_field_description = @notes_field[‘description’]
@notes_field_condition = Condition.find_name_by_id(@notes_field[‘condition_id’])
end

Now, views/manage_notes_records/list.rhtml

<h1>Listing notes_records</h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Condition</th>
<th>Experiment</th>
</tr>
<% for notes_record in @notes_records %>
<tr>
<td><%= notes_record.id %></td>
<td><%= notes_record.name %></td>
<td><%= notes_record.description %></td>
<td><%= Condition.find_name_by_id(notes_record.condition_id) %></td>
<td><%= Experiment.find_name_by_id(Condition.find_experiment_id_by_id(notes_record.condition_id)) %></td>
<td><%= link_to ‘Show’, :action => ‘show’, :id => notes_record %></td>
<td><%= link_to ‘Edit’, :action => ‘edit’, :id => notes_record %></td>
<td><%= link_to ‘Destroy’, { :action => ‘destroy’, :id => notes_record }, :confirm => ‘Are you sure?’, :method => :post %></td>
</tr>
<% end %>
</table>
<br /><%= link_to ‘New notes_record’, :action => ‘new’ %>

(update the controller as/if appropriate)

Update app/views/manage_students/list.rhtml

<h1>Listing students</h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Condition</th>
<th>Experiment</th>
</tr>
<% for student in @students %>
<tr>
<td><%= h student.id %></td>
<td><%= h student.name %></td>
<td><%= h Condition.find_name_by_id(student.condition_id) %></td>
<td><%= h Experiment.find_name_by_id(Condition.find_experiment_id_by_id(student.condition_id)) %></td>
<td><%= link_to ‘Show’, :action => ‘show’, :id => student %></td>
<td><%= link_to ‘Edit’, :action => ‘edit’, :id => student %></td>
<td><%= link_to ‘Destroy’, { :action => ‘destroy’, :id => student }, :confirm => ‘Are you sure?’, :method => :post %></td>
</tr>
<% end %>
</table>
<%= link_to ‘Previous page’, { :page => @student_pages.current.previous } if @student_pages.current.previous %>
<%= link_to ‘Next page’, { :page => @student_pages.current.next } if @student_pages.current.next %>
<br />
<%= link_to ‘New student’, :action => ‘new’ %>

and other files as appropriate

add to student.rb

def self.find_name_by_id(selected_argument_id)
student = find(selected_argument_id)
@to_return = student.name
end

def self.find_condition_id_by_id(selected_argument_id)
student = find(selected_argument_id)
@to_return = student.condition_id
end
end

to app/views/manage_notes/list.rhtml

<h1>Listing notes</h1>
<table>
<tr>
<th>ID</th>
<th>Student</th>
<th>Note Record</th>
<th>Note Field</th>
<th>Notetext</th>
<th>Condition</th>
<th>Experiment</th>
</tr>
<% for note in @notes %>
<tr>
<td><%= note.id %></td>
<td><%= Student.find_name_by_id(note.student_id) %></td>
<td><%= NotesRecord.name_from_id(note.notes_record_id) %></td>
<td><%= NotesField.name_from_id(note.notes_field_id) %></td>
<td><%= note.notetext %></td>
<td><%= Condition.find_name_by_id(Student.find_condition_id_by_id(note.student_id)) %></td>
<td><%= Experiment.find_name_by_id(Condition.find_experiment_id_by_id(Student.find_condition_id_by_id(note.student_id))) %></td>
<td>
<% for column in Note.content_columns %>
<td><%=h note.send(column.name) %></td>
<% end %>
<td><%= link_to ‘Show’, :action => ‘show’, :id => note %></td>
<td><%= link_to ‘Edit’, :action => ‘edit’, :id => note %></td>
<td><%= link_to ‘Destroy’, { :action => ‘destroy’, :id => note }, :confirm => ‘Are you sure?’, :method => :post %></td>
</tr>
<% end %>
</table>
<%= link_to ‘Previous page’, { :page => @note_pages.current.previous } if @note_pages.current.previous %>
<%= link_to ‘Next page’, { :page => @note_pages.current.next } if @note_pages.current.next %>
<br /><%= link_to ‘New note’, :action => ‘new’ %>

(note how there’s both name_from_id and find_name_by_id arguments. Yick!

But for now, we just finished the sixth day of work. Now…

Rest.

Chinese in the Gap

Perlez, J. (2007). Militant students capture masseuses to make a point.” New York Times. June 24, 2007.


Chinese Prostitutes Masseuses

If there’s anything that illustrates how screwy Pakistan, and for that matter the rest of the Islamic Gap, is, it’s this:

“There were about 25 Chinese women, dressed only in underpants and bras,” recalled Ms. Okasha, 24, a muscular high-school badminton champion who had shed her black garb for soft mauves, her face uncovered, during an interview inside the women-only confines of the school. “They scattered, but we managed to grab five.”

Though a concluded paragraph isn’t bad, either:

Ms. Hassan, her face absent of makeup but her fingernails and toenails varnished with red, said she was proud of her raiders.

“I said to the students before they went off, ‘The Chinese are masters at karate; you don’t know how to make one kick.’ But they were able to manage.”

And for completeness sake:

His college-age students asked “many times,” he said, about the legitimacy of suicide bombing. Suicide bombing was justifiable against American soldiers. “It depends on the circumstances,” he said. “In a supermarket I will say no. Suicide bombing against American soldiers in Iraq and Afghanistan, I will say yes, yes. It’s not suicide. It’s a mission, then it’s allowed.”

Two take-aways from this article:


Girl, decapitalized

First, it’s interesting that the New York Times describes what are obviously prostitutes as “masseuses.” The reason is clear: opposition to prostitution should be an intellectual, liberal exercise, and not a goonish one. The Times is clearly embarrassed to be intellectually on the same side as madrassa-studying reactionaries, though this isn’t surprising. Both the New York Times and the Islamists prefer prostitution to remain in the informal, depriving many women of a natural capitalization vehicle. Both the the Pakistani extremists and the old liberals of the New York Times share the disdain for market exchange, Hernando de Soto-style capitalization of private wealth, and liberty. Both share a sentimental opposition and a thuggish adoration of enforced virtue.

Secondly, the story highlights the transition of China from the Gap to the Core. China is in the unusual condition that while she is becoming a global leader, she has a large reservoir of very low paid citizens. This means that while the United States, Europe, and Japan find their capital flowing oversees in a process of creative destruction, China finds her people innovatively moving abroad for profits. This creates friction, and while the the typical American “downside” is lost capital, the increasingly typical Chinese “downside” is lost lives.

tdaxps_new_map_md
China: On the Frontlines of the Gap

China and the West share a common interest, not only in energy resources, but in a better administration of the Gap.

Finishing a Basic Student Interface and Building a Basic Output Interface

Getting up at 2:30 AM (completely accidentally) has its advantages. I listened to an episode of mysterious universe, got the below programming work done, read the paper, drank a pot of coffee, chatted with friends, ate two meals, and lumbered again… all before noon.


A laptop at work

Notes-on-Rails-wise, two main accomplishments today: finished up the student interface and also created a basic output interface. Neither of these are pretty, and there’s no CSS to be seen yet. However, this is solid progress, not only in the project, but as importantly in my understanding of the framework.


Behold!

The day’s work was built around a simple motto: “A good programmer is lazy, and rubyonrails makes it easy to be a good programmer.”


Instead of figuring out by reading documentation how to update students and notes into database, instead create static scaffolds for the students and notes model. Then we will integrate them into our student interface

First, edit the condition model with the line

has_many :students

Then generate two more static scaffolds, as we did on the second day

ruby script/generate scaffold student manage_students
ruby script/generate scaffold note manage_notes

That done, we will finish up the static scaffolds before we use code from here

Set the _form.rhtml partial in manage_student’s form partial to

<%= error_messages_for ‘student’ %>
<!–[form:notes_field]–>
<p><label for="student_name">Name</label><br/>
<%= text_field ‘student’, ‘name’ %></p>
<p><label for="student_condition_id">Condition ID</label><br/>
<%=
@conditions = Condition.find(:all, :order => "name" ).map {|u| [u.name, u.id] }
select :student, :condition_id, @conditions
%></p>
<!–[eoform:notes_field]–>

This works, but the controller doesn’t show anymore… let’s fix that

Change show in manage_student’s controller to

def show
@student = Student.find(params[:id])

@student_name = @student[‘name’]
condition = Condition.find(@student[‘condition_id’])
@student_condition = condition.name
end

and the _show.rhtml partial to

<p>
<br /><b>Name</b>: <%= @student_name %>
<br /><b>Condition</b>: <%= @student_condition %>
</p>
<%= link_to ‘Edit’, :action => ‘edit’, :id => @notes_record %> |
<%= link_to ‘Back’, :action => ‘list’ %>

For a reason I’m not clear about (how’s that for confidence!) the show function does not work, as it onyl shows the id but not other fields. But I have an idea.

We generated the scaffold before we generated the controller. Does this matter?

Who knows. But let’s go through the steps properly. First, let’s destroy our static scaffolds

Warning: This is a mistake, but unlike most mistakes, will wrongly destroy the student.rb and note.rb. I use jEdit to recover lost files!

ruby script/generate scaffold student manage_students
ruby script/generate scaffold note manage_notes

Now generate the controllers

ruby script/generate controller manage_students
ruby script/generate controller manage_notes

Now put in the line scaffold :student or scaffold :note, respectively, in these files.

Eep! The destroy accidentally destroyed student.rb and note.rb. No problem. I’ll open jEdit which I use for text editing and which autosaves everything, and recover it. Now it works fine, and we can even see the data we inputed.

That done, regenerate the stattic scaffold the same way we did before

ruby script/generate scaffold student manage_students
ruby script/generate scaffold note manage_notes

Woot! That works fine. So let’s go back now and rejigger manage_student’s _form like it was before.

And it works!

Now for the experiment… trying to put this code in the students controller (the one being worked on for the past few days).

First take that form we created and move it over to the _select_condition.rhtml partial in app/views/students

<%= form_remote_tag(:update => "notetaking_display",
:url => { :action => :select_notes_from_condition },
:position => "top" ) %>
Your Condition:
<%= select :student, :condition_id, @conditions %>
<p><label for="student_name">Your Name</label><br/>
<%= text_field ‘student’, ‘name’ %></p>
<%= submit_tag "Select Condition" %>
<%= end_form_tag %>
<div id="notetaking_display"></div>

And wahoo! While looking at the previously generated code (specifically app/controllers/manage_students_controller.rb#create) I see the .save() function that saves an object to the database. So change student_controller.rb#select_notes_from_condition to

def select_notes_from_condition
@student = Student.new(params[:student])
@student.save

@notes_fields = NotesField.find_by_condition(@student.condition_id)
@notes_records = NotesRecord.find_by_condition(@student.condition_id)

render :partial => “notes_view”
end

and the student is added to the database just fine.

Note to self: the next goal is to make sure that student is in the session and also save the notes. Using the universal .save method, we’ll do essentially the same thing here, too:

In app/controllers/students_controller.rb:

def select_notes_from_condition
@student = Student.new(params[:student])
@student.save
session[:student] = @student;

@notes_fields = NotesField.find_by_condition(@student.condition_id)
@notes_records = NotesRecord.find_by_condition(@student.condition_id)

render :partial => “notes_view”
end

def save_student_notes
@student = session[:student]

@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
@note = Note.new(
:notetext => params[note_field.name][note_record.name],
:student_id => @student.id
)
@note.save
end
end
render_text “Notes Updated”
end

And let’s clean up the _notes_view partial a little too:

<h1>Note-Taking Matrix</h1>
<%= form_remote_tag(:update => "notetaking_display",
:url => { :action => :save_student_notes },
:position => "top" ) %>
<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 h(notes_field.name), h(notes_record.name), :cols => 20, :rows => 8 %></td>
<% end %>
</tr>
<% end %>
</table>
<%= submit_tag "Save Notes" %>
<%= end_form_tag %>
<div id="notetaking_display" name="notetaking_display"></div>

The last big thing to do is to create the code that will display the student records we already have. However, I accidentally deleted student.rb and note.rb. Thus I need to re-create them as they should be. student.rb should now be:

class Student < ActiveRecord::Base
belongs_to :condition

has_many :notes

def self.find_students(selected_condition_id)
@students = Student.find(:all, :conditions => [‘condition_id = ?’ , selected_condition_id ] )
end
end

and note.rb is:

class Note < ActiveRecord::Base
belongs_to :student

def self.find_notes(selected_student_id)
@students = Note.find(:all, :conditions => [‘student_id = ?’ , selected_student_id ] )
end
end

To do this, create a new controller called output

ruby script/generate controller output

First, some prepwork

in condition.rb, add the function

def self.find_conditions_array(selected_experiment_id)
@conditions = Condition.find(:all, :conditions => [‘experiment_id = ?’ , selected_experiment_id ] )
end

In the new app/controllers/output_controller.rb file, create a new function called index

def index
@experiments = Experiment.find(:all)
for experiment in @experiments
@conditions = Condition.find_conditions(experiment.id)
for condition in @conditions
@students = Student.find_students(condition)
for student in @students
@notes = Note.find_notes(condition)
end
end
end
end

Now for the app/view/index.rhtml

<html><head><title>Output for Notes on Rails</title></head>
<body>
<h1>Output Listing</h2>
<% for experiment in @experiments %>
<h2>Experiment <i><%= experiment.name %></i></h2>
<% for condition in Condition.find_conditions_array(experiment.id) %>
<h3>Condition <i><%= condition.name %></i></h3>
<% for student in Student.find_students(condition.id) %>
<h4>Student <i><%= student.name %></i></h3>
<% for note in Note.find_notes(student.id) %>
<p><%= note.notetext %></p>
<% end %>
<% end %>
<% end %>
<% end%>
</body>
</html>

Roh roh! A quick test reveals that the notes table does not save record or field information, making it impossible to reconstruct what went where. This can be solved by retrofitting some code and doing a new migration, but it’s still frustrating.

Go back in the notes to when the basic administration interface was finished to alter the notes table

ruby script/generate migration alter_notes

This generates 014_alter_notes.rb, which should read (after editing)

class AlterNotes < ActiveRecord::Migration
def self.up
add_column :notes, :notes_field_id, :integer
add_column :notes, :notes_record_id, :integer
end

def self.down
remove_column :notes, :notes_field_id
remove_column :notes, notes_record_id
end
end

Then rake db:migrate

In notes_field.rb and notes_record.rb, add the function (from Agile Web Development with Rails, 28)

def self.name_from_id(selected_id)
@entries = find(selected_id);
@entries.name
end

Then, index.rhtml in output’s view:

<html><head><title>Output for Notes on Rails</title></head>
<body>
<h1>Output Listing</h2>
<% for experiment in @experiments %>
<h2>Experiment <i><%= experiment.name %></i></h2>
<% for condition in Condition.find_conditions_array(experiment.id) %>
<h3>Condition <i><%= condition.name %></i></h3>
<% for student in Student.find_students(condition.id) %>
<h4>Student <i><%= student.name %></i></h3>
<% for note in Note.find_notes(student.id) %>
<p><i>On the <%= NotesField.name_from_id(note.notes_field_id) %> of <%= NotesRecord.name_from_id(note.notes_record_id) %></i>: <%= note.notetext %></p>
<% end %>
<% end %>
<% end %>
<% end%>
</body>
</html>

And your done!

Tomorrow: making it pretty.