Hi fellow RoR’ers,
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.
@email = Email.find(:all, :conditions => [ “mail = ?”,
“%#{params[:mail]}%”])
@email.delete(:id)
Any ideas?
@email = Email.find(:all, :conditions => [ “mail = ?”,
“%#{params[:mail]}%”])
@email.delete(:id)
You don’t need the % around that parameter. That’s used for LIKE
queries. Try this:
@email = Email.find(:all, :conditions => [ “mail = ?”, params[:mail]]
Steve
Still doesn’t seem to work.
The app doesn’t give an error, but nothing gets deleted from the
database either.
iSocrates wrote:
Hi fellow RoR’ers,
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.
@email = Email.find(:all, :conditions => [ “mail = ?”,
“%#{params[:mail]}%”])
@email.delete(:id)
Any ideas?
to destroy a record where you know the email address do
Email.find_by_mail(params[:email][:mail]).destroy!
Yeah,
Seems to work now, but without the ‘!’ after destroy
Thanks a lot!