Ask A Question

Notifications

You’re not receiving notifications from this thread.

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'

Reply

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

Reply

Hello, yeah, in the first case, you get only one record and it doesn't have collection methods like "destroy_all"

Reply

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. ¯_(ツ)_/¯

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.