We are working with nested attributes and we’ve reached a point where we’re not sure if there is a better, clearer, “more rails” way of dealing with it.
We have 3 models - Organisation, Category and a strictly join table CategoryOrganisation (no additional attributes). The relation between Organisation and Category is many-to-many.
Now, we want to create a form with checkboxes through which the categories for organisations can be added and removed. The example form would look like that:
Now, the form should behave like that:
newaction is hit, it should show all categories - unchecked,
createaction is hit, but validations are not passing it should render the
newview, but keeping the checkboxes that were selected,
editaction is hit, is should show all categories and current categories of the edited organisation should be checked,
updateare successful, flow is redirected to
We don’t want to spoil your minds with our custom solution, but to get to know if there is a clear, Rails solution for that.
In our opinion, there is no such solution in Rails documentation, as we found out reading following sources:
API documentation doesn’t get to many-to-many relation, which is the case in our app.
In advance, thanks for help!