1

I am looking for a way to add a lot of records at ones in ActiveAdmin. To be more specific, I have 2 models: Stores and Programs. Stores have many Programs.

I don't mind adding a Store using standard ActiveAdmin create view. But I would like a faster way to add programs in a spreadsheet-like way. I looked into best_in_place (https://github.com/bernat/best_in_place) but it doesn't do do adding records, just editing them.

Any suggestions? I would really appreciate it.

user527662
  • 363
  • 5
  • 14

1 Answers1

0

The short answer is Rails has nothing to help you do this. Rails has a defined convention for editing multiple objects if they belong to another object that can accept nested attributes for a few reasons, the most important of which is that there's a place to aggregate validation, as well as a standard way to differentiate each set of fields (the id). Neither of these are true during creation.

You can, however, manually work around this a couple of ways.

  1. would be to simply write out the forms yourself, and put the logic to loop through them in your controller. This is going to be fragile, and you'll have issues getting validation to work properly, however.

  2. would be to either create a new class that handles this single case, or try and adapt your existing Store class to handle nested attributes. There's a very solid explanation of how to do this here.

Community
  • 1
  • 1
sgrif
  • 3,702
  • 24
  • 30
  • Thanks, I will look into both solutions (not sure which one is going to be less headache or worth it in the end) – user527662 Aug 16 '12 at 14:22
  • I think you're better off having an additional submit tag called "submit and add another" or something along those lines, and in your controller having it render new again if that was the submit tag used. – sgrif Aug 16 '12 at 16:13
  • By the way, "submit and add another" is exactly what I ended up doing (works great for now) – user527662 Sep 14 '12 at 00:24