NoMethodError:未定义的方法`detect'表示false:FalseClass

时间:2016-11-03 17:27:50

标签: ruby-on-rails ruby

我正在尝试创建一个对象,但我得到一个非常奇怪的错误,我不知道它来自哪里,甚至如何调试它。

PushNotification.new(user_id: 7, notification_type: 'foo')

NoMethodError: undefined method `detect' for false:FalseClass
from /usr/local/bundle/gems/activemodel-4.2.3/lib/active_model/attribute_methods.rb:471:in `match_attribute_method?'
from /usr/local/bundle/gems/activemodel-4.2.3/lib/active_model/attribute_methods.rb:457:in `respond_to?'
from /usr/local/bundle/gems/activerecord-4.2.3/lib/active_record/attribute_methods.rb:236:in `respond_to?'
from /usr/local/bundle/gems/activerecord-4.2.3/lib/active_record/attribute_assignment.rb:56:in `rescue in _assign_attribute'
from /usr/local/bundle/gems/activerecord-4.2.3/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
from /usr/local/bundle/gems/activerecord-4.2.3/lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
from /usr/local/bundle/gems/activerecord-4.2.3/lib/active_record/attribute_assignment.rb:35:in `each'
from /usr/local/bundle/gems/activerecord-4.2.3/lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
from /usr/local/bundle/gems/activerecord-4.2.3/lib/active_record/core.rb:564:in `init_attributes'
from /usr/local/bundle/gems/activerecord-4.2.3/lib/active_record/core.rb:281:in `initialize'
from /usr/local/bundle/gems/activerecord-4.2.3/lib/active_record/inheritance.rb:61:in `new'
from /usr/local/bundle/gems/activerecord-4.2.3/lib/active_record/inheritance.rb:61:in `new'
from (irb):58
from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands/console.rb:110:in `start'
from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands/console.rb:9:in `start'
from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:in `console'
from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'

我的架构是这样的:

create_table "push_notifications", force: :cascade do |t|
  t.integer  "user_id",           limit: 4,   null: false
  t.string   "notification_type", limit: 191, null: false
  t.datetime "created_at",                    null: false
  t.datetime "updated_at",                    null: false
end

这可能来自哪些想法?

1 个答案:

答案 0 :(得分:0)

我错误地使用保留字作为函数名称引发了此错误。

帮助其他可能遇到此问题的人:

http://www.rubymagic.org/posts/ruby-and-rails-reserved-words