# DangerousAttributeError

**URL:** <https://www.ruby-forum.com/t/dangerousattributeerror/143866>\
**Category:** Rails\
**Created:** [July 23, 2008, 11:54am UTC](https://www.ruby-forum.com/t/dangerousattributeerror/143866 "2008-07-23T11:54:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 23, 2008, 11:54am UTC](https://www.ruby-forum.com/t/dangerousattributeerror/143866/1 "2008-07-23T11:54:10Z")

</div>

I upgraded to rails 2.0.2  
so i get this error  
ActiveRecord::DangerousAttributeError in Asset#show

this is in the view

\<%=h shekels\_to\_dollars(@asset.price\_shekel, options = {:precision =\> 0}) %\>

when i delete this line every thing is ok

This is in application helper  
#Converts a shekels amount to a dollar amount and outputs as a  
currency.  
def shekels\_to\_dollars (amount\_in\_shekels, options = {})  
@dollar = Rate.find(1).rate  
if amount\_in\_shekels  
amount\_in\_dollars = amount\_in\_shekels.to\_f / @dollar.to\_f  
return number\_to\_currency(amount\_in\_dollars, options)  
end  
end

this is the db table  
class CreateRates \< ActiveRecord::Migration  
def self.up  
create\_table :rates do |t|  
t.column :name, :string  
t.column :rate, :float, :default =\> 0  
t.column :update, :date  
t.column :updated\_at, :datetime  
end  
end

def self.down  
drop\_table :rates  
end  
end

Please help

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 23, 2008, 11:59am UTC](https://www.ruby-forum.com/t/dangerousattributeerror/143866/2 "2008-07-23T11:59:30Z")

</div>

Raised when attribute has a name reserved by Active Record (when  
attribute has name of one of Active Record instance methods).

In your case that’s most likely the “update” attribute, since it would  
overwrite ActiveRecords update method

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 30, 2008, 9:50pm UTC](https://www.ruby-forum.com/t/dangerousattributeerror/143866/3 "2008-07-30T21:50:45Z")

</div>

Thanks Thorsten

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 7, 2008, 12:26am UTC](https://www.ruby-forum.com/t/dangerousattributeerror/143866/4 "2008-08-07T00:26:00Z")

</div>

Is renaming the attribute at the database level the only option to  
work around this issue?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 7, 2008, 3:24pm UTC](https://www.ruby-forum.com/t/dangerousattributeerror/143866/5 "2008-08-07T15:24:26Z")

</div>

At work we have similar situation where many other applications/  
platforms make use of the same database table so changing the schema  
incurs more risk that simply ensuring that the Rails App can play  
along so when it’s not possible to change the column name on a table  
how do you fix this issue?

For instance how do you map an accessor from a column in the db that  
clashes with an existing method provided by ActiveRecord::Base?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 11, 2008, 4:44pm UTC](https://www.ruby-forum.com/t/dangerousattributeerror/143866/6 "2008-08-11T16:44:58Z")

</div>

Hi Robert,

On Aug 7, 3:23 pm, Robert N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> At work we have similar situation where many other applications/  
> platforms make use of the same database table so changing the schema  
> incurs more risk that simply ensuring that the Rails App can play  
> along so when it’s not possible to change the column name on a table  
> how do you fix this issue?
> 
> For instance how do you map an accessor from a column in the db that  
> clashes with an existing method provided by ActiveRecord::Base?

This thread should offer a solution to your problem:  
[http://groups.google.com/group/compositekeys/browse\_thread/thread/edda7b7370b45608](http://groups.google.com/group/compositekeys/browse_thread/thread/edda7b7370b45608)

Cheers,  
Marco
