As per readme of simple_form (https://github.com/plataformatec/simple_form), the f.association helper is available with the collection option which accepts the collection of objects that you want to provide for select list. You can use :
f.association :driver, collection: Driver.unassociated, label_method: :name, value_method: :id # In Driver modelclass Driver < ActiveRecord::Base scope :unlinked, -> { where(car_id: nil) } end *How to ensure validation before saving, to avoid problems of concurrent accesses?* For validation you can use uniqueness validation as : class Driver < ActiveRecord::Base validates_uniqueness_of :car_id end This way when any object of Driver is saved it will be checked that weather the car_id was taken earlier or not and so the same car_id will not be assigned to more than one driver. Thanks, Lauree On Sunday, April 20, 2014 1:01:02 AM UTC+5:30, Ricardo do Valle wrote: > > I have two models (Car and Driver) and a combobox to select which driver > belongs to which car. I want the combobox just show the objects that have > not yet been associated. > > # vehicle belongs_to: driver > # driver has_one: vehicle > # simple_form # vehicle/_form.html.haml > = f.association: driver, label_method: :name, value_method: :id > > How to ensure validation before saving, to avoid problems of concurrent > accesses? > > Thanks > -- 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+unsubscr...@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/f300c623-b0b9-40e9-99b8-c3bc119dab61%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.