I have an activeadmin resource which has a belongs_to :user relationship.
When I create a new Instance of the model in active admin, I want to associate the currently lo
As per the AA source code this worked for me:
controller do
def call_before_create(offer)
end
end
Another option:
def create
params[:item].merge!({ user_id: current_curator.id })
create!
end
I ran into a similar situation where I didn't really need to completely override the create method. I really only wanted to inject properties before save, and only on create; very similar to your example. After reading through the ActiveAdmin source, I determined that I could use before_create
to do what I needed:
ActiveAdmin.register Product do
before_create do |product|
product.creator = current_user
end
end
You are right active admin use InheritedResources
, all other tools you can see on the end of the page.