[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

the noob

6/23/2006 9:24:00 PM

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.

8 Answers

senthil.nayagam@gmail.com

6/24/2006 3:45:00 AM

0

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://senthiln...

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.

the noob

6/25/2006 5:25:00 PM

0

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?

Martin DeMello

6/25/2006 7:44:00 PM

0

the noob <vehement82@hotmail.com> 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

senthil.nayagam@gmail.com

6/25/2006 9:17:00 PM

0

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://senthiln...


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?

Timothy Goddard

6/25/2006 10:16:00 PM

0

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.

the noob

6/26/2006 3:55:00 PM

0

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/google_web_accelerator_hey_not_so_fast_an_alert_for_web_app_des...

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

6/26/2006 6:47:00 PM

0

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

6/29/2006 7:10:00 PM

0

Just want to confirm that the above steps solved my problem.