attr_accessor, not able to access property

后端 未结 4 1693
旧巷少年郎
旧巷少年郎 2021-01-23 10:29

This is probably very stupid question but here we go

class Foo < ActiveRecord::Base
 attr_accessor :group_id
end

From irb

4条回答
  •  無奈伤痛
    2021-01-23 10:38

    If you have a column by the name group_id in the table, than ActiveRecord defines the accessor for you. When you overwrite it as you did, your calls simply searches for a regular instance variable named group_id, which returns nil.

提交回复
热议问题