난 컬럼 이름 attribute
을 사용하여 일부 테이블과 기존의 데이터베이스있어. 우리의 전체 어플리케이션을 다시 컴파일한다는 의미에서이 이름을 바꿀 수는 없습니다. DB를 액세스하려고 할 때ActiveRecord :: DangerousAttributeError - 속성? ActiveRecord에 의해 정의됩니다
, 내가 끝낼 :
attribute? is defined by ActiveRecord
첫 번째가 내가 datamapper를 사용하여 시도하지만 난 그것에서 얻을 수없는 자신이 파괴되어서는 안 물건을 고정 발견하고 - 같은 중첩 된 속성 .... 그래서
, 나는 다시 아칸소에 왔어요하고 문제를 해결하기 위해이를 사용하고 있습니다 :
class Radcheck < ActiveRecord::Base
set_table_name 'radcheck'
class << self
def instance_method_already_implemented?(method_name)
return true if method_name == 'attribute?'
return true if method_name == 'attribute_before_type_cast'
return true if method_name == 'attribute='
return true if method_name == 'attribute'
return true if method_name == 'attribute_changed?'
return true if method_name == 'attribute_change'
return true if method_name == 'attribute_will_change!'
return true if method_name == 'attribute_was'
return true if method_name == 'attribute_column'
return true if method_name == 'reset_attribute!'
super
end
end
end
을하지만 그 혼란 그리고 때 실제로 그럴 내 주위를 어지럽히 y를 사용하고 테이블에 액세스하십시오 ...
이 작은 놈을 감싸는 좋은 방법이 있습니까?
아마도이 질문에 대한 해결책은 도움이 될 수 있습니다. http://stackoverflow.com/questions/5428987/how-can-i-use-activerecord-on-a-database-that-has-a-column-named -attribute-d – JofoCodin
이 또한 도움이 될 수 있습니다 : http://stackoverflow.com/questions/4348037/overriding-or-aliasing-name-of-column-in-legacy-database-using-rails-activerecor – sparrovv
I @radcheck = Radcheck.all (: select => 'attribute as attr'). 하지만 여전히 오류가 발생합니다. –