我有这个模型
class Contestcode < ActiveRecord::Base
attr_accessible :code, :used
def self.is_valid(code)
valid = false
contestcode = Contestcode.where('code = ?', code)
Rails.logger.debug("My object: #{contestcode.inspect}");
if (contestcode)
valid = contestcode.used
end
valid
end
end
当我尝试运行时,self.is_valid
出现此错误:
undefined method `used' for #<ActiveRecord::Relation:0x007ff525fde1a8>
调试语句的输出是:
My object: [#<Contestcode id: 1, code: "aaaaa", used: false, created_at: "2013-01-23 10:21:32", updated_at: "2013-01-23 10:21:32">]
如何获得比赛代码的 used 属性?