在这里开始RoR程序员......
在IRB中,我有一个从数据库表中检索的哈希。我想在这个哈希(.select,.keys等)上执行Hash类方法,但是当我尝试这样做时,我得到NoMethodError。我在这里错过了什么基本概念?
编辑:这是控制台输出
2.0.0-p247 :020 > vote_record.keys
NoMethodError: undefined method `keys' for #<Vote:0x00000002736f98>
from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activemodel- 4.0.0/lib/active_model/attribute_methods.rb:436:in `method_missing'
from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:131:in `method_missing'
from (irb):20
from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>
答案 0 :(得分:0)
您的vote_record
不是Hash
,而是Vote
(继承自ActiveRecord::Base
类)实例。