Thank you guys, you helped us a lot! Great to have you around :).

Piotr


W dniu środa, 20 kwietnia 2016 20:04:59 UTC+2 użytkownik Stewart Mckinney 
napisał:
>
> Piotr, have a look at 
> http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
>
> There are a ton of things that are auto-created by associations - one is a 
> setter method that reflects the id's of the association. 
> #collection_check_boxes basically formats your input to match that setter. 
> In this case it would be "category_ids".
>
> On Wed, Apr 20, 2016 at 1:54 PM, Frederick Cheung <[email protected] 
> <javascript:>> wrote:
>
>> On Wednesday, April 20, 2016 at 2:26:20 PM UTC+1, Piotr Brych wrote:
>> > OK, thanks for that, it might help.
>> >
>> >
>> > But how would you in this case send params back to `create` or `update` 
>> to respectively know which associations (category_organisations) should be 
>> created and which deleted?
>>
>> Assigning to category_ids will create/delete rows in the join table as 
>> appropriate.
>>
>> Fred.
>> >
>> > Thanks,
>> > Piotr
>> >  
>> >
>> >
>> > W dniu wtorek, 19 kwietnia 2016 17:19:21 UTC+2 użytkownik Frederick 
>> Cheung napisał:
>> >
>> >
>> >
>> >
>> > As long as you don't want the same form to be usable to create new 
>> categories, I wouldn't use nested attributes at all.
>> >
>> >
>> > f.collection_check_boxes :category_ids, Category.all, :id, :name
>> >
>> >
>> > will render a checkbox and label for each category, and the check box 
>> will be ticked if category_ids contains the element (there are plenty of 
>> options to customise the generated markup). I'm not entirely sure what 
>> happens if you assign to foo_ids but the overall save fails and rolls back. 
>> If you run into issues there  I'd add a virtual attribute to hold the 
>> assigned ids and actually set category_ids  from a before_save or similar.
>> >
>> >
>> > Fred                                    
>>
>> --
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/rubyonrails-talk/8b2c9630-8070-4ae8-8bf5-8749f77cb992%40googlegroups.com
>> .
>> 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/d3fe067d-5611-4dc6-9ba7-580c6e55e878%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to