I have a Rails 4.1 application that uses several well-known technologies.
Simple form, Cocoon
I'm having trouble deleting records that are nested attributes. Based on some lengthy research, I believe that my code is correct, however, maybe I am missing something stupid.
Model
has_many :staff_services_joins, :dependent => :destroy has_many :services, :through => :staff_services_joins accepts_nested_attributes_for :staff_services_joins, :allow_destroy => true
This is a little unorthodox, but I have two components on the join model that are not foreign keys and need to be installed. This is why I accept nested attributes for the join model, and not for the service model.
Controller method
def update ap staff_params
Strong parameters
params.require(:staff).permit( :user_id, :store_id, :avatar, :remote_avatar_url, :first_name, :last_name, :email, :active, :admin, :staff_services_joins_attributes => [ :staff_id, :service_id, :price, :duration, :_destroy ] )
Hash Parameter Update Example
{ "store_id" => "2", "avatar" => "avatar.png", "remote_avatar_url" => "", "first_name" => "Joshua", "last_name" => "Tyree", "email" => " joshuat@createthebridge.com ", "active" => "0", "admin" => "1", "staff_services_joins_attributes" => { "0" => { "service_id" => "2", "price" => "50.00", "duration" => "30", "_destroy" => "1" } }
}
Based on this, this thing should destroy this model, but for some reason this, of course, is not so. Any help is most definitely appreciated.