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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Steve Bartholomew
2007-Feb-02 13:40 UTC
Re: Delete an entry from database, after user input
> > @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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Still doesn''t seem to work. The app doesn''t give an error, but nothing gets deleted from the database either. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yeah, Seems to work now, but without the ''!'' after destroy Thanks a lot! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---