Begginers Rails Issue - destroy method being called out of the blue

Discussion in 'Ruby' started by the noob, Jun 23, 2006.

  1. the noob

    the noob Guest

    Hello, I'm just starting with ruby-rails and having a weird issue.
    Starting from a basic scaffolding I've altered the list method/view to
    display a group of images. Im using file_column for file handling.
    Since I got the basics working I've had an issue with items
    disappearing off my list. Now that i've learned to use the logs I see
    that the destroy method is being called, but im not doing it. I have
    protected the method with the :confirm option on the link and a
    "before_filter :login_required" in the controller. So I'll be coding
    away switching from my list view to another im working on over and over
    and suddenly one of the images is gone. When I looked into it I see
    that the record has been deleted from the database and file column has
    done its thing and removed the image file from my file system. I can't
    find other people complaining about this so I'm guessing i've made a
    coding error. Any tips on how to troubleshoot this?

    Probably unrelated but I have one other issue with the destroy method.
    The link I use on my list view to call destroy has the :confirm option.
    But when I test it I sometimes get an error saying the item is not
    found. So I tried clicking the link and didn't do anything to the
    confirm message that popped up. I checked my database and filesystem
    and the entry is already gone. The logs indicate that the destroy
    method was called. With the confirm dialog still onscreen. ??

    I'm running on windows/apache 2/scgi. This issue has occured on cgi,
    fcgi, and scgi.

    Thanks for reading.
    the noob, Jun 23, 2006
    #1
    1. Advertising

  2. Strange problem,

    never faced this problem

    could you confirm from your apache log calls to "destroy" are "POST"
    requests and not "GET"

    if they are post and it is your browser, could be browser bug, please
    try some other browser, firefox, opera or internet explorer

    if they are get requests, in your destroy action verify request method
    is post in your destroy method.


    if request.post?
    #destroy action
    else
    flash[:notice]="illegal delete call"
    end

    hope this helps for now,


    regards
    A.Senthil Nayagam

    http://senthilnayagam.com

    the noob wrote:
    > Hello, I'm just starting with ruby-rails and having a weird issue.
    > Starting from a basic scaffolding I've altered the list method/view to
    > display a group of images. Im using file_column for file handling.
    > Since I got the basics working I've had an issue with items
    > disappearing off my list. Now that i've learned to use the logs I see
    > that the destroy method is being called, but im not doing it. I have
    > protected the method with the :confirm option on the link and a
    > "before_filter :login_required" in the controller. So I'll be coding
    > away switching from my list view to another im working on over and over
    > and suddenly one of the images is gone. When I looked into it I see
    > that the record has been deleted from the database and file column has
    > done its thing and removed the image file from my file system. I can't
    > find other people complaining about this so I'm guessing i've made a
    > coding error. Any tips on how to troubleshoot this?
    >
    > Probably unrelated but I have one other issue with the destroy method.
    > The link I use on my list view to call destroy has the :confirm option.
    > But when I test it I sometimes get an error saying the item is not
    > found. So I tried clicking the link and didn't do anything to the
    > confirm message that popped up. I checked my database and filesystem
    > and the entry is already gone. The logs indicate that the destroy
    > method was called. With the confirm dialog still onscreen. ??
    >
    > I'm running on windows/apache 2/scgi. This issue has occured on cgi,
    > fcgi, and scgi.
    >
    > Thanks for reading.
    Senthilnayagam, Jun 24, 2006
    #2
    1. Advertising

  3. the noob

    the noob Guest

    Thanks Senthilnayagam, The logs show the destroy requests are GET. I
    put the code you proveded into my method and i'm getting the illegal
    delete call error whe I use the delete link. I take it that these
    requests should be POST? I don't see any options availble on the
    destroy method. Any suggestions on a fix?
    the noob, Jun 25, 2006
    #3
  4. the noob <> wrote:
    > Thanks Senthilnayagam, The logs show the destroy requests are GET. I
    > put the code you proveded into my method and i'm getting the illegal
    > delete call error whe I use the delete link. I take it that these
    > requests should be POST? I don't see any options availble on the
    > destroy method. Any suggestions on a fix?


    if request.post? wasn't pesudocode - it's the actual syntax to see if
    the incoming request is a POST :)

    Can't remember the syntax offhand, but there's also a way to use a
    before_filter to protect a bunch of actions at once from being called by
    anything other than a POST - ask on the rails mailing list.

    martin
    Martin DeMello, Jun 25, 2006
    #4
  5. So my assumption was right, your browser was the culprit

    some browser plugins, trozans, seem to access all the url's we browse
    and send it back to their core sites.

    test with a alternative browser, remove the offending plugin.

    scaffold is supposed to get you a kickstart, but anything that goes
    production, especially the code which is not under password protection
    and accessible by bots and public should be duly tested

    regards
    A.Senthil Nayagam
    http://senthilnayagam.com


    the noob wrote:
    > Thanks Senthilnayagam, The logs show the destroy requests are GET. I
    > put the code you proveded into my method and i'm getting the illegal
    > delete call error whe I use the delete link. I take it that these
    > requests should be POST? I don't see any options availble on the
    > destroy method. Any suggestions on a fix?
    Senthilnayagam, Jun 25, 2006
    #5
  6. Are you using a web accelerator of some sort? These will load links on
    pages and often ignore javascript confirmation dialogs. You can block
    them by looking for telltale headers.

    the noob wrote:
    > Hello, I'm just starting with ruby-rails and having a weird issue.
    > Starting from a basic scaffolding I've altered the list method/view to
    > display a group of images. Im using file_column for file handling.
    > Since I got the basics working I've had an issue with items
    > disappearing off my list. Now that i've learned to use the logs I see
    > that the destroy method is being called, but im not doing it. I have
    > protected the method with the :confirm option on the link and a
    > "before_filter :login_required" in the controller. So I'll be coding
    > away switching from my list view to another im working on over and over
    > and suddenly one of the images is gone. When I looked into it I see
    > that the record has been deleted from the database and file column has
    > done its thing and removed the image file from my file system. I can't
    > find other people complaining about this so I'm guessing i've made a
    > coding error. Any tips on how to troubleshoot this?
    >
    > Probably unrelated but I have one other issue with the destroy method.
    > The link I use on my list view to call destroy has the :confirm option.
    > But when I test it I sometimes get an error saying the item is not
    > found. So I tried clicking the link and didn't do anything to the
    > confirm message that popped up. I checked my database and filesystem
    > and the entry is already gone. The logs indicate that the destroy
    > method was called. With the confirm dialog still onscreen. ??
    >
    > I'm running on windows/apache 2/scgi. This issue has occured on cgi,
    > fcgi, and scgi.
    >
    > Thanks for reading.
    Timothy Goddard, Jun 25, 2006
    #6
  7. the noob

    the noob Guest

    Thank you for your responses. The code Senthilnayagam provided has
    stopped me from loosing data but now I cannot run the destroy method
    myself. When I click the destroy link it is making a GET request.
    >From your respounses I take it that this should be POST. Any idea why

    my own requests are being processed as GET's? This happens on fresh
    copies of IE and firefox.

    *Timothy Goddard* - Thanks for that tip. I do use google web
    accelerator and you prompted me to do some research. I found this
    article:

    http://37signals.com/svn/archives2/...ot_so_fast_an_alert_for_web_app_designers.php

    Which sounds exactly like the problem I'm having. I'm putting in the
    code to stop prefetching now. I will let it roll for a few days and
    come back with the results. Although the GET/POST issue is
    interesting the prefetching plug-in may be the root cause.
    the noob, Jun 26, 2006
    #7
  8. the noob

    the noob Guest

    I got it.. have to add a {post => true} to my link_to helper. Again,
    thanks for your help :). I'm still going to cut off google pre-cache.
    the noob, Jun 26, 2006
    #8
  9. the noob

    the noob Guest

    Just want to confirm that the above steps solved my problem.
    the noob, Jun 29, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Player
    Replies:
    7
    Views:
    339
    Player
    Aug 25, 2004
  2. Jay
    Replies:
    10
    Views:
    853
    Christos Georgiou
    Apr 12, 2006
  3. Ook
    Replies:
    2
    Views:
    313
  4. Tomás Ó hÉilidhe

    Compiling source code out of the blue

    Tomás Ó hÉilidhe, Jan 2, 2008, in forum: C Programming
    Replies:
    16
    Views:
    444
    Tomás Ó hÉilidhe
    Jan 4, 2008
  5. Felix
    Replies:
    1
    Views:
    328
    Felix
    Sep 29, 2006
Loading...

Share This Page