Question

I have in my model:

attr_accessible :name, as: :admin

And in my active admin initializer:

module ActiveAdmin
  class BaseController
    with_role :admin
  end
end

Is it possible to get the role that is editing the record in the model, to do something like this:

validate :thing, if: ->{ modifier == :admin }

?

Was it helpful?

Solution

I used an attr_accessor for now:

class Service
  attr_accessor :modifier
  attr_accessible ..., :modifier, as: :admin

And I send it from the form:

ActiveAdmin.register Service do
  form do |f|
    f.input :modifier, as: :hidden, input_html: { value: :admin }
    ...

Then I could use it like this:

validate :something

def something
  if modifier == 'admin'
     # some code here
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top