我之前发过但是代码没有正确显示。我正在尝试编写一个逻辑来计算电信站点(如微波站和变电站)的功率储备,...... 我已经创建了一个site_type scaffold,并在数据库mysql中进行了以下迁移
MySQL的
id site_type
1 Substation
2 Generating Station
3 District Office 4 VHF_UHF Repeater
5 Capacitor Station
6 Office
7 Microwave Station
这是网站模型
class Site < ActiveRecord::Base
attr_accessible :lat, :long, :site_code, :site_name, :site_type, :site_type_id
def is_microwave?
self.site_type = 'Microwave Station'
end
def is_under_capacity?(capacity)
(is_microwave? && capacity < 24) || (!is_microwave? && capacity < 8)
end
观众中的代码
- total_capacity = @site.dc_power_inventories.sum {|d| d.dc_power_supply.battery.capacity.capacity } rescue 0
- total_amps = @site.equipment_inventories.sum {|e| e.equipment.amp.amp } rescue 0
- capacity_left = (total_capacity.to_f / total_amps).round(2) rescue 0
div.row-fluid
h4
span Site Name: #{@site.site_code}
span.pull-right Capacity Reserve Left: #{capacity_left}
/ h4 = "Capacity Reserve Left: #{capacity_left} Hrs "
- if @site.is_under_capacity?(capacity_left)
div.alert
strong Warning !!!
span You Must add or replace the DC power system.
我遇到的问题是,当网站(微波炉或其他网站)容量不足(<24小时)时,我才会收到警告。我想要的是当容量低于24小时时获得微波站点类型的警告并且警告其他站点为&lt; 8小时保留容量。
感谢。
答案 0 :(得分:0)
可能是错的,但我认为你对微波的测试是错误的,认为你错过了一个=符号
def is_microwave?
self.site_type == 'Microwave Station'
end