的ActiveRecord :: DangerousAttributeError [英] ActiveRecord::DangerousAttributeError
问题描述
我要连接到用于我们的freeradius服务器现有的数据库。一个表有一个称为列属性,我想访问。
I have to connect to an existing database used by our freeradius server. One table has a column called attribute which I'm trying to access.
访问时,我得到了自己的错误:
When accessing, I get his error:
ActiveRecord::DangerousAttributeError
attribute? is defined by ActiveRecord
我试着选择并在我的模型重命名此列:
I've tried to select and rename this column in my model:
def self.default_scope
Radcheck.select("attribute as newattribute")
end
但是,这不是任何工作。
But that's not working either.
谁能推荐解决的办法?我真的很想重命名列轨道!
Can anyone recommend a way around this? I'd really like to rename the column in rails!
推荐答案
在一个类似的问题,我发现这个答案:的http:// stackoverflow.com/a/9106597/1266906
On a similar question I found this answer: http://stackoverflow.com/a/9106597/1266906
而不必关心这些属性通过的ActiveRecord在Rails的3.0保留只需添加
Without having to care about which attributes are reserved by ActiveRecord in Rails 3.0 just add
gem 'safe_attributes'
你的的Gemfile
和创业板会自动尝试采取一切碰撞名称的照顾。
to your Gemfile
and the gem will try to take care of all colliding names automatically.
至于其他的答案,你需要使用 Radcheck [:属性]
或 Radcheck.read_attribute:属性
/ Radcheck.write_attribute:属性,价值
与内部保留的名称接入领域,但创业板,能够保证象验证 validates_ presence_of:属性
将照常工作。
As with the other answer you need to use Radcheck[:attribute]
or Radcheck.read_attribute :attribute
/ Radcheck.write_attribute :attribute, 'value'
to access fields with internally reserved names, but the gem ensures validations like validates_presence_of :attribute
will work as usual.
进一步的细节可在 https://github.com/bjones/safe_attributes
这篇关于的ActiveRecord :: DangerousAttributeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!