Thanks for the reply, but I think I didn't explain the question clearly. Let me try with an example
There are 3 tasks (Task.all) T1: Get loaf of bread T2: Kiss a frog T3: Hack on simple_form Let's create user Jim, all 3 tasks are available, 0 pre-selected. We assign T1 and T2 to him. So TaskAssignment now contains 2 entries, both active. Next edit user Jim, all 3 tasks are available, T1 and T2 pre-selected. We take T2 off Jim. I've implemented the logic, so that the TaskAssignment, which links Jim and T2 will be deactivated (NOT deleted). NOW, edit user Jim again. I need to make ALL 3 tasks available, but ONLY T1 pre-selected. This is what I couldn't figure out... How to make simple_form only pre-select T1, but not both T1 and T2 ... On Friday, 24 August 2012 22:07:48 UTC+10, Craig Read wrote: > > ...or... > > f.association :task_assignments, collection: TaskAssignment.actives.all > > On Fri, Aug 24, 2012 at 10:07 PM, Craig Read <[email protected]<javascript:> > > wrote: > >> I've not used simple_form. >> >> But looking at the docs, what you want is: >> >> f.association :task_assignments, collection: TaskAssignment.actives >> >> On Fri, Aug 24, 2012 at 1:24 PM, marsbomber <[email protected]<javascript:> >> > wrote: >> >>> Hi guys, >>> >>> This seems to be a pretty common thing, but I just cannot figure it out >>> ... I opened a thread on the simple_form group already, but I thought I'll >>> ask the smart brains here too :) >>> >>> I have a has_many through association >>> >>> class User >>> has_many :task_assignments >>> has_many :tasks, through: :task_assignments >>> end >>> >>> class TaskAssignment >>> belongs_to :user >>> belongs_to :task >>> >>> scope :actives, where("disabled = ?", false) >>> scope :inactives, where("disabled = ?", true) >>> end >>> >>> class Task >>> has_many :task_assignments >>> has_many :users, through: :task_assignments >>> end >>> >>> On TaskAssignment, I have a disabled boolean field. >>> >>> On the user form, I want to list all non-disabled TaskAssignments, but >>> by default >>> >>> f.association :task_assignments, collection: Task.all >>> >>> selects all assignments including the disabled ones. >>> >>> How do I make f.association not pre-select disabled task assignments, >>> when I'm editing an existing user? >>> >>> Thanks >>> Jim >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby or Rails Oceania" group. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msg/rails-oceania/-/_YQPp4CcGt0J. >>> To post to this group, send email to [email protected]<javascript:> >>> . >>> To unsubscribe from this group, send email to >>> [email protected] <javascript:>. >>> For more options, visit this group at >>> http://groups.google.com/group/rails-oceania?hl=en. >>> >> >> >> >> -- >> Craig Read >> >> @Catharz >> https://github.com/Catharz >> http://stackoverflow.com/users/158893/catharz >> >> > > > -- > Craig Read > > @Catharz > https://github.com/Catharz > http://stackoverflow.com/users/158893/catharz > > -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To view this discussion on the web visit https://groups.google.com/d/msg/rails-oceania/-/lAuuWr6rKO0J. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
