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.

Leave a Reply

Your email address will not be published. Required fields are marked *