我正在訪問我無法更改的數據庫,並且它有一個名爲attribute
的列已定義。任何時候我嘗試訪問一個attribute
,我會得到以下例外:如何在具有名爲'attribute'的列的數據庫上使用ActiveRecord? (DangerousAttributeError)
屬性?
class User < ActiveRecord::Base
def self.authenticate(username,password)
where(:username => username, :value => password).first
end
end
我發現在軌道上的郵件列表爲解決這一問題,但對我
class << self
def instance_method_already_implemented?(method_name)
return true if method_name == 'attribute'
super
end
end
不行的紅寶石計劃:由ActiveRecord的(ActiveRecord的:: DangerousAttributeError)
我的代碼定義
我不知道它是否重要,但這裏是我的環境的細節:
- ruby 1.9.2p0(2010-08-18 revisi上 29036)[x86_64的-darwin10.4.0]
- 滑軌
- 3.0.1 ActiveRecord的(3.0.1)的ActiveResource(3.0.1)
UPDATE(解決):
PLAN甲:
select("username, value").where(:username => username, :value => password).first
是「屬性?」還是「屬性」的例外情況?注意問號在哪裏。 – 2011-03-25 06:10:27
關於'attribute?'的例外。名爲'attribute' – jean 2011-03-25 06:18:02