ActiveAdmin: load and use models from other engine doesn't work

478 views Asked by At

I followed the guide in the wiki to use my models from my engine in my main-app with active admin.

The only thing I must change (that doesn't mentioned in the wiki) was this:

if defined?(ActiveAdmin)
  ActiveAdmin.register Blog::Category do
  end
end

I just added: Blog::. In my engine "Blog" I added a model named "category" with a name:string attribute. But when I add one in active admin the field name wasn't saved in the database. My request parameters are:

{"utf8"=>"✓", "authenticity_token"=>"PzKDTcoJZ6Sy2tXgw9WSwXiR7aZp81lOtBvfD5Ec3F72H5L7MEMLjlOFgKWQBo2U4n9mPc7AgjcIS3MTIY2nZA==", "category"=>{"name"=>"asdasd"}, "commit"=>"Update Category", "id"=>"1"}

any ideas why it isn't saved in the databse? When I create a new one, the record is created but without my input.

1

There are 1 answers

1
Erik Perkins On BEST ANSWER

I ran into the same problem. I was able to get the resources to save properly by overriding the activeadmin controller actions (in e.g. app/admin/category.rb) like this

ActiveAdmin.register Blog::Category do

  permit_params :the, :parameters, :for, :your, :resource

  controller do
    def create
      @category = Blog::Category.new permitted_params[:category]
      if @category.save
        notice = 'Category was successfully created.'
        redirect_to admin_blog_category_url(@category), notice: notice
      else
        render :new
      end
    end
  end
end

I'm not sure exactly what's going on in the default case yet, but my guess is that the activeadmin controller action is not creating the object in the right namespace - that is, it does something like @category = Category.new rather than @category = Blog::Category.new. A similar override appears to be necessary for the :update action as well.