Rails: activeadmin overriding create action

后端 未结 4 1126
渐次进展
渐次进展 2021-01-30 12:34

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

4条回答
  •  青春惊慌失措
    2021-01-30 13:13

    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
    

提交回复
热议问题