A
A
Andrey Fedorov2015-04-18 21:02:38
Ruby on Rails
Andrey Fedorov, 2015-04-18 21:02:38

How to make adding a child element in ActiveAdmin?

I have products and categories. Now, when creating/editing a product, I simply select a category from the list.
I would like to make it so that when viewing a category in the admin panel, there would be a button "Add product to category" and that would be redirected to the product creation page, where the parent category is already selected.
Can this be done at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Miroshnichenko, 2015-05-03
@4b65696e

Hello, you need to add a link to create a product in the show block in category.rb, something like this

show do
    attributes_table do
      div do
        link_to 'New product', new_admin_category_product_path(category_id: category)
      end
    end
  end

For more details on how to customize show, see activeadmin.info/docs/6-show-pages.html
Next, you need to specify in product.rb that there is a connection with the category, like
this You can read about it here activeadmin.info/docs/2-resource-customization .html
Don't forget to put links in the rails models.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question