Forum: Ruby on Rails Making AR attriibutes private

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Tim C. (Guest)
on 2006-03-07 19:50
(Received via mailing list)

Can anyone tell me the syntax to make AR attributes private so that they
can only be set through an object's constructor?

I want do something like this, where item_id and rated_by are private
and set only through the constructor:

# Schema as of Mon Mar 06 21:22:59 BRT 2006 (schema version 15)
#  id                  :integer(11)   not null
#  item_id             :integer(11)   default(0), not null
#  rated_by            :integer(11)   default(0), not null
#  created_on          :datetime      not null
#  updated_on          :datetime      not null

class Wow < ActiveRecord::Base
  belongs_to :item
  validates_presence_of :item_id, :rated_by

  def initialize(item, user)
    self.item_id =
    self.rated_by =


How do I make item_id and rated_by private and still accessible
internally by the constructor?


Tim C.
This topic is locked and can not be replied to.