我有一个国家模型和一个旅行笔记模型。 一个国家有许多旅行记录,旅行记录属于一个国家。
在Rails控制台中:
TravelNote.published.country(248)
[#<TravelNote id: 172, country_id: 248, status: 1, advice_against: 0, published_at: "2012-10-04 07:57:00", created_at: "2014-09-23 09:09:20", updated_at: "2014-09-23 09:09:20">]
TravelNote.published.country(248).published_at
NameError: undefined local variable or method `published_at' for #<Class:0x00000005a84968>
如何获取此对象的published_at属性?
答案 0 :(得分:5)
TravelNote.published.country(248)
返回一个记录数组,因此你必须抓住数组的第一项:
TravelNote.published.country(248).first.published_at