Forum: Ruby on Rails Active Records with column privilages

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.
D28d6de06f3492ecd56fa6c45aac5dc0?d=identicon&s=25 My Name (vsg)
on 2009-04-13 21:23
Hey I am making applications that has different DB roles to the same
database. One is pretty much the admin access where the person can see
all the columns in each table, then there is the regular joe DB role
where I don't let him see confidential information that only admin can
see, for security purposes, so I put column privileges on that role. The
problem with that is the fact that Rails do not see these privileges set
by the DB and Rails gets all the columns in a table. I do not want it to
do that. I wish to prevent those columns from showing in the model. Is
this possible?
D28d6de06f3492ecd56fa6c45aac5dc0?d=identicon&s=25 My Name (vsg)
on 2009-04-13 22:38
nvm, i checked out ActiveRecord::Base and I found no such thing. But I
did find a nice patch that was made 2 years ago

I changed it around to this to match the the code in rails 2.2.2

       # Hide columns from active record
       def attr_hidden(*attributes)
         write_inheritable_attribute(:attr_hidden, + (hidden_attributes || []))

       def hidden_attributes # :nodoc:

and changed ActiveRecord::Base.column ofcourse

      # Returns an array of column objects for the table associated with
this class.
      def columns
        unless defined?(@columns) && @columns
          @columns = connection.columns(table_name, "#{name}
Columns").delete_if {|c| attr_hidden.member?(}
          @columns.each { |column| column.primary = ==
primary_key }

wish something like this is implemented. in my mind it is pretty useful.
Ofcourse i do wish it could be a lil bit more automated by looking into
the DB for the column privileges, but this is cool. =D
This topic is locked and can not be replied to.