0
我有3个模型,客户,包和位置。在Ruby On Rails中使用ActiveRecord 3
客户登录,并可以查看其包裹的位置时间表。
class Location < ActiveRecord::Base
def find_all_by_customer(customer)
self.joins(:packages => :customer).where("customers.id = ?", customer).select("DISTINCT(locations.id), locations.name, locations.created_at")
end
返回客户对他的所有包的所有位置,这样他们就可以在时间轴上显示。
我正在努力的部分,然后显示每个这些位置旁边的包装号。问题是软件包编号依赖于current_user和位置。
<% @locations.each do |location| %>
<%= location.name %>
<%= # Want to display all package numbers in this location for the logged in user. %>
<% end %>
什么是软件包号码,它如何取决于current_user和location? – Flauwekeul 2011-05-28 17:02:04
这只是该软件包的独特参考。这取决于用户,因为用户正在接收该包,并且该包取决于位置,因为该包必须随时位于某个位置。 – pingu 2011-05-28 17:08:34
那么包号是如何定义的?每次更改包的位置时它是否生成?我没有看到它在你的select语句中查询。对不起,我不明白它应该如何工作:) – Flauwekeul 2011-05-28 22:49:56