mysql - how to delete record from a join table in rails -


i have join table having 2 record list_id , car_id. want delete record list_id = 5 , car_id = 7 example. here code in controller section:

def deletejoin   @car = car.find(params[:id])   end   def destroyjoin     #  car = car.find(params[:id])     #  list = list.find(params[:list_id])     # car = car.find(21.to_i)     # list = list.find(8)     #  puts car     #  puts list      car = car.find(params[:id])      @list = car.lists.find(params[:list_id])      cars_lists.where(car_id: 25).destroy_all     #  @list.cars.where(:id => params[:id]).destroy_all     #  @list = @car.cars_lists.find(params[:list_id])     # @list.destroy     # car = car.find(params[:id]).destroy     flash[:notice] = "car #{car.name} destoryed successfully"     redirect_to(:action => 'index', :list_id => @list.id)   end 

try this,

def delete_join     car = car.find(params[:id])     list = list.find(params[:list_id])     carslists.where(car_id: car.id, list_id: list.id).destroy_all end 

this code delete records join table car_lists matching car_id , list_id.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -