j9fseg
Last Updated: February 25, 2016
·
566
· jalada
Profile picture may 2012

Allow all attributes to be changed by admins

Using ActiveSupport Concerns it's really easy to enable all fields to be editable in RailsAdmin (or your own admin dashboard) through attr_accessible roles. Create a file called app/models/extensions/adminable.rb and put this in it:

module Extensions
  module Adminable
    extend ActiveSupport::Concern

    included do
      send(:attr_accessible, *(column_names + [{as: :admin}])) if table_exists?
    end
  end
end

Then for every model you want to be fully editable by an admin, add this line:

include Extensions::Adminable

If you're using RailsAdmin, add

config.attr_accessible_role { :admin }

to the configure block in your RailsAdmin initializer.

Say Thanks
Respond