Have you looked at
http://apidock.com/rails/v4.0.2/ActionView/Helpers/FormOptionsHelper/collection_check_boxes
? Seems to be exactly what you want.

On Tue, Apr 19, 2016 at 11:07 AM, Piotr Brych <[email protected]> wrote:

> 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:
>
>
> [image: form1]
> <https://cloud.githubusercontent.com/assets/12682792/14636248/993263cc-062a-11e6-85a2-de8388a75a3f.PNG>
>
>
> 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:
>
>    - http://guides.rubyonrails.org/form_helpers.html,
>    - http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html
>    ,
>    -
>    
> http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
>    .
>
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/f61e6b1f-958f-4018-b73f-b5495ebef2a8%40googlegroups.com
> <https://groups.google.com/d/msgid/rubyonrails-talk/f61e6b1f-958f-4018-b73f-b5495ebef2a8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CA%2BCQ936iC8C_PzMdzM-v4um30yETySHEnwf8GbuOLZfGw3iO_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to