Sharing Passwords Between Users Discussion
Hello ROR developers, anyone facing a error when try to delete a user that you share a password ?
----------- code
def destroy
@password = current_user.passwords.find(params[:password_id]).destroy_all
redirect_to @password
end
---------------- error
undefined method `destroy_all'
Hey me from future, I tried to delete this question but I can not, the problem of course was me, the code I had to write is this :
def destroy
@password.user_passwords.where(user_id: params[:id]).destroy_all
redirect_to @password
end
after his everything works well
Hello, yeah, in the first case, you get only one record and it doesn't have collection methods like "destroy_all"
maybe you mention this later on but creating a unique restraint on user_passwords is probably better than destroy_all.
I know it's intended to be a more contrived example but I'd also want to be able to remove a user from all passwords if, for instance, "we broke up" lol. So something like a user_shared join table and then make the user_passwords dependent on destroy. ¯_(ツ)_/¯