I am developing a web application with Ruby on Rails/Jquery Mobile.
The SQLite ‘Inventory’ schema consists of existingfixture:string, replacementfixture:string, and quantity:integer. There are two other tables called oldlights and newlights. These simply contain the options for existingfixtures and replacementfixtures, respectively. Oldlights and newlights both have lightname:string and value:integer, where value is how many Watts the given light name uses.

I also want my program to display, the difference in watts from existing to replacement fixture. I want to be able to have another column saying how many Watts are saved anually, but I have no idea how to go about this. The values are associated in oldlights/newlights. However, I can’t figure out how to access them and perform mathematical equations with them in a seperate column.
Code for Displaying values from database:
<fieldset class="ui-grid-c"><center>
<div class="ui-block-a"><%= inventory.existing %></div>
<div class="ui-block-b"><%= inventory.replacement %></div>
<div class="ui-block-c"><%= inventory.quantity %></div>
<div class="ui-block-d"><%= link_to 'Remove', [inventory.client, inventory],
:confirm => 'Are you sure?',
:method => :delete %></div></center>
</fieldset>
Code for adding inventory
<%= form_for([@client, @client.inventories.build]) do |f| %>
<fieldset class="ui-grid-c">
<div class="ui-block-a"><%= f.select :existing, Olight.all.collect{|p| [p.name]}, { :include_blank => true } %></div>
<div class="ui-block-b"><%= f.select :replacement, Nlight.all.collect{|p| [p.name]}, { :include_blank => true } %></div>
<div class="ui-block-c"><%= f.number_field :quantity, "data-mini" => "true" %></div>
<div class="ui-block-d"></div>
</fieldset>
<%= f.submit 'Add Inventory'%>
<% end %>
Sebastien is partly correct. (Parsing the fixture name won’t work, since in the “1-4′ 40W-T12-ESMB” naming, 40 isn’t the wattage of the fixture, but that of a single 4 foot T-12 lamp, and the engineering isn’t as simple as the wattage of a “3-4′ 40W-T12-ESMB” fixture == 3 times the wattage of a “1-4′ 40W-T12-ESMB” fixture. The aggregate fixture wattage depends on a number of other factors in addition to lamp wattage.)
You should read a this page! “Section 3 – Making Select Boxes with ease” for more information on how to setup your drop lists — I like to construct using options_for_Select. I believe you want the form where the name is displayed, but the id of the old and new fixtures is what is stored in your database.
In your rails controller when you are saving an inventory combination (existing, replacement, and count), you use the old and new fixture ids to look up their wattages, do the math, then store the savings value. When the page is displayed, all the data should be present.
On a style note, I’d move the Olight/Nlight.all.collect code out of the page template and into the controller, setting up instance variables to be used by the view…