我正在尝试创建一个对象,但我得到一个非常奇怪的错误,我不知道它来自哪里,甚至如何调试它。
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
这可能来自哪些想法?
答案 0 :(得分:0)