I just ran into a strange error. In console I typed in following:
ruby-1.9.2-p290 :120 > User.first.to_json
User Load (0.7ms) SELECT `users`.* FROM `users` LIMIT 1
=>
"{\"avatar_id\":10,\"email\":\"peter@example.org\",\"firstname\":\"Peter\",\"lastname\":\"L\",\"user_role_id\":11}"
and when I try that with an avatar:
ruby-1.9.2-p290 :121 > Avatar.first.to_json
Avatar Load (0.5ms) SELECT `avatars`.* FROM `avatars` LIMIT 1
NoMethodError: Attribute Load (0.8ms) SELECT `attributes`.* FROM
`attributes` WHERE `attributes`.`avatar_id` = 10
undefined method `keys' for #<ActiveRecord::Relation:0x007fb6a3e69518>
Why on earth can I convert the user model to json but not the avatar?!
I just ran into a strange error. In console I typed in following:
ruby-1.9.2-p290 :120 > User.first.to_json
User Load (0.7ms) SELECT `users`.* FROM `users` LIMIT 1
=>
"{\"avatar_id\":10,\"email\":\"peter@example.org\",\"firstname\":\"Peter\",\"lastname\":\"L\",\"user_role_id\":11}"
and when I try that with an avatar:
ruby-1.9.2-p290 :121 > Avatar.first.to_json
Avatar Load (0.5ms) SELECT `avatars`.* FROM `avatars` LIMIT 1
NoMethodError: Attribute Load (0.8ms) SELECT `attributes`.* FROM
`attributes` WHERE `attributes`.`avatar_id` = 10
undefined method `keys' for #<ActiveRecord::Relation:0x007fb6a3e69518>
Can you show us the start of avatar.rb and attribute.rb?
Also I just wonder whether attribute is a reserved word in RoR.