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

T

the noob

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.
 
S

Senthilnayagam

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
 
T

the noob

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?
 
M

Martin DeMello

the noob said:
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
 
S

Senthilnayagam

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
 
T

Timothy Goddard

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.
 
T

the noob

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.
 
T

the noob

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top