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.