我正在为他的老板在度假时调试一个rails应用程序。我们有一个公司使用的应用程序,我们可以使用它来填写时间表和查看客户票。在打开的故障单页面上,有一个列,其中包含故障单的简要说明。我们在Ubuntu上有一个用于生产的环境,以及一个用于开发的XP环境,这两个环境都没有遇到这个bug。但是,如果我在Windows 7或更新版本上运行环境,则描述不会显示为字符串,而是显示为BigDecimal,通常为“0.0”,其中一些票证会显示其他数字。我会发布截图,但我不会为了公司的隐私。
这是我目前所知道的:我们使用的数据库显示表中的实际描述。视图和控制器都显式转换为字符串,当我在代码中删除.to_s
时,错误仍然存在。我将类类型发送到日志文件,以确认它是一个BigDecimal。从我的机器运行生产代码时,错误仍然存在。我认为这可能是操作系统兼容性问题。或者在数据库和应用程序本身之间的某个地方,数据正在一个我还不知道的文件中转换为BigDecimal。我正在运行rails 3.0.7和ruby 1.9.2p290
以下是我认为可疑的代码:
<div id="page_center">
<div id="branding_row">
<%= label_tag("Show_Open", "Show Open Tickets",{:class => 'page_label'}) -%>
</div>
<div id="tabs">
<ul>
<% @locationHash.keys.each do |keyItem| %>
<li><a href="#tabs-<%= keyItem %>"><%= keyItem %></a></li>
<% end %>
</ul>
<% @locationHash.keys.each do |keyItem| %>
<div id="tabs-<%= keyItem %>">
<table >
<tr >
<th style="width:50px; empty-cells:hide;">WO#</th>
<th style="width:125px; empty-cells:hide;">Customer Name</th>
<th style="width:125px; empty-cells:hide;">Description</th>
<th style="width:65px; empty-cells:hide;">Tech</th>
<th style="width:125px; empty-cells:hide;">Date/Time</th>
</tr>
<% @locationHash[keyItem].each do |ticketItem| %>
<tr>
<td><%= ticketItem.work_order.to_s %></td>
<td><%= ticketItem.customer_name.to_s %></td>
<td><%= ticketItem.woDesc.to_s %></td>
<td><%= ticketItem.tech.to_s %></td>
<td><%= ticketItem.created_at.to_s %></td>
</tr>
<% end %>
</table>
</div>
<% end %>
</div>
</div>
<div id="right_column">
</div>
这是控制器:
class TicketsController < ApplicationController
def populate_workOrders
@customerId = params[:customerID]
logger.debug "@customerId = #{@customerId.to_s}"
@tickets = Ticket.where(:customer_id => @customerId)
logger.debug "@tickets size = #{@tickets.size.to_s}"
@outputTickets = Array.new
@tickets.each {|ticketItem|
#select only tickets with specific open/usable codes
if ['ARV','CAN','COM','D','H','O','S','PERM','CB','CN'].include?( ticketItem.woStatus )
logger.debug "workorder - #{ticketItem.work_order} status - #{ticketItem.woStatus}"
@outputTickets << ticketItem
end
}
respond_to do |format|
format.json { render :json => @outputTickets.to_json }
end
end
def show_open
logger.debug "****** inside Tickets - show_open ******"
@customersHash = Hash.new
@locationHash = Hash.new
@tempTicketArray = Array.new
# @customers = Customer.all
# logger.debug "@customers size = #{@customers.size.to_s}"
# @customers.each {|customerItem|
# @customersHash[customerItem.id] = customerItem
# }
## updates names
# @allTickets = Ticket.all
# @allTickets.each{|ticketItem|
# ticketItem.customer_name = @customersHash[ticketItem.customer_id].name
# ticketItem.save
# }
@tickets = Ticket.where(woStatus: ['ARV','CAN','COM','D','H','O','S'])
logger.debug "@tickets size = #{@tickets.size.to_s}"
@tickets.sort_by!{|y| [y.work_order]}.reverse!
@tickets.each {|ticketItem|
logger.debug "#{ticketItem.customer_name.to_s } + #{ticketItem.woDesc.class}"
if @locationHash.has_key?(ticketItem.office)
@locationHash[ticketItem.office] << ticketItem
else
@locationHash[ticketItem.office] = Array.new
@locationHash[ticketItem.office] << ticketItem
end
}
@locationHash.keys.each {|keyItem|
logger.debug "#{keyItem} array size = #{@locationHash[keyItem].size.to_s}"
@locationHash[keyItem].each{|ticketItem|
logger.debug "#{ticketItem.customer_name.to_s } - #{ticketItem.woDesc.class}"
}
}
end
end
这是schema.rb,省略了无关的部分:
create_table "customers", :force => true do |t|
t.string "number"
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "entries", :force => true do |t|
t.string "customer"
t.string "work_order"
t.text "description"
t.string "arrival_time"
t.string "depart_time"
t.integer "day_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "timesheet_order"
t.integer "user_id"
t.boolean "submitted"
t.integer "ticket_id"
t.integer "customer_id"
t.integer "type_id"
t.integer "productivityType"
end
create_table "ticket_import", :id => false, :force => true do |t|
t.string "srvStat"
t.string "offId"
t.string "callNbr"
t.string "custName"
t.string "priorityLevel"
t.string "svcDescr"
t.string "techId"
t.string "endDte"
t.string "custNum"
end
create_table "tickets", :force => true do |t|
t.string "work_order"
t.integer "customer_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "woStatus"
t.string "office"
t.text "woDesc"
t.string "tech"
t.string "entDate"
t.string "customer_name"
end