I have a Rails app, where a user can subscribe and unsubscribe from a
mailinglist. To unsubscribe, the user can fill in their email address
in a form field.
But I have no idea how to delete the record from the database, using
the typed in data from the user. I’ve tried it with the following
code, but doesn’t seem to work.
There’s no instance method #delete, AFAIK. What does @email contain?
Should you be using be “params[:email][:mail]” instead? A shorter way
to do it would be with Email.destroy_all, or, if you’re really sure,
Email.delete_all.
Thanks for the help! (with a ‘!’)
I’m happy it worked for you, but if it was me, I’d certainly be
digging down deeper. “Oh it just works now” doesn’t usually satisfy
me as a developer. Calling #destroy instead of #destroy! shouldn’t
make a fleck of difference as to whether or not Email responds to #find_by_mail. Y’know?
It’s up to you. You’re welcome either way.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.