【发布时间】:2012-06-06 04:13:17
【问题描述】:
我正在使用 Ruby on Rails/Jquery Mobile 开发一个 Web 应用程序。
SQLite 'Inventory' 模式由existingfixture:string、replacementfixture:string 和quantity:integer 组成。还有另外两个表,称为 oldlights 和 newlights。这些仅包含分别用于现有夹具和替换夹具的选项。 Oldlights 和 newlights 都有 lightname:string 和 value:integer,其中 value 是给定灯光名称使用的瓦数。
我还希望我的程序显示现有灯具与替换灯具的瓦数差异。 我希望能够有另一列说明每年节省多少瓦特,但我不知道该怎么做。这些值在 oldlights/newlights 中关联。但是,我不知道如何访问它们并在单独的列中使用它们执行数学方程。
从数据库中显示值的代码:
<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>
添加库存的代码
<%= 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 %>
【问题讨论】:
标签: ruby ruby-on-rails-3 html jquery-mobile sqlite