This blog is part of our Rails 5 series.
Sometimes we need to ignore a database column. However Rails 4.x doesn't have any officially defined method which ignores a database column from Active Record. We can apply our patch on model to ignore certain columns.
1class User < ActiveRecord::Base 2 3 # Ignoring employee_email column 4 def self.columns 5 super.reject {|column| column.name == 'employee_email'} 6 end 7 8end
Rails 5 added ignored_columns
Rails 5 has added ignored_columns to ActiveRecord::Base class.
Here is revised code after using ignored_columns method.
1class User < ApplicationRecord 2 self.ignored_columns = %w(employee_email) 3end