Is there a way to make Rails ActiveRecord attributes private?

Jordini was most of the way there

Most of active_record happens in method_missing. If you define the method up front, it won’t hit method_missing for that method, and use yours instead (effectively overwriting, but not really)

class YourModel < ActiveRecord::Base

  private

  def my_private_attribute
    self[:my_private_attribute]
  end

  def my_private_attribute=(val)
    write_attribute :my_private_attribute, val
  end

end

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)