Ruby on Rails Tuesday, April 19, 2016

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:


form1


Now, the form should behave like that:

  • when new action is hit, it should show all categories - unchecked,
  • when create action is hit, but validations are not passing it should render the new view, but keeping the checkboxes that were selected,
  • when edit action is hit, is should show all categories and current categories of the edited organisation should be checked,
  • when create and update are successful, flow is redirected to show action.

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!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f61e6b1f-958f-4018-b73f-b5495ebef2a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment