SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Association Type Mismatch error Deleting contacts

    Hey,

    I have a new error that I can't seem to fix that is occuring whilst I try to delete contacts from my basic Contact App.

    At the moment I am defining the destroy action in my contacts controller as:

    Code:
      
       def destroy
       current_user.contacts.delete(params[:id])
       redirect_to index_path
       end
    In my view I have:

    Code:
    <%= button_to 'Delete', contact, :method => :delete %>
    and the error I am getting is:

    Code:
    ActiveRecord::AssociationTypeMismatch in ContactController#destroy 
    Contact(#24465528) expected, got String(#10155204)
    Any help people can offer on this really would be much appreciated!

    Thanks,
    Tom

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay turned out I managed to work it out myself in the end. The working implementation I have gone with is this:

    Controller

    Code:
    def destroy
      contact = current_user.contacts.find(params[:id])
      contact.destroy
       redirect_to index_path
      end
    and View

    Code:
    <%= button_to 'Delete', contact, :method => :delete %>
    Hopefully this will help someone who is stuck in the future


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •