1

I should note before any of this, that my friend pulled from my git repo and it works perfectly for him.

The database has the attribute, and the attr_accessible is set. But Rails is throwing this error undefined method 'is_free' for #<Account:0x007fb53bc91ec0> when trying to access it in view.

Database for ref: t.boolean "is_free", :default => false

The other really bizarre thing is you can see the attribute exists in console.

1.9.3p194 :005 > a.is_free
 => false 

I have dropped, created and re-migrated the database without success. I have deleted the entire folder, re-cloned from git and re-created database without success.

I have no idea what is going on.. it's just acting haywire. Please help, I'm losing my mind.

4

2 回答 2

1

改变

a.update_attribute(:is_free, :true)

a.update_attribute(:is_free, true)
于 2013-08-29T18:41:43.913 回答
1

只有当您请求它获取该列的方式时,这样的方法才存在。默认情况下它是这样工作的,但是可以限制加载哪些列select

找出您拥有哪些数据的一种非常简单的方法是将其放在您的视图中:

raise a.attributes.inspect

a有问题的记录在哪里。is_free如果已加载,您应该会看到一个属性。如果没有,log/development.log请查看执行了什么SELECT查询。

于 2013-08-29T19:19:06.093 回答