Rails的Find_by_id产生异常 [英] Rails Find_by_id raises exception
问题描述
我认为,导致Object.find和Object.find_by_id之间的不同之处在于发现将引发 RecordNotFound 的异常而find_by_id简单地返回零,如果没有被发现。
I was led to believe that the difference between Object.find and Object.find_by_id is that find will raise a RecordNotFound exception whereas find_by_id simply returns nil if nothing is found.
不过,在我的Rails应用程序3,如果我试图寻找我的上传模型与一个假身份证,我得到:
However, in my Rails 3 app if I attempt to search my Uploads model with a bogus id I get:
的ActiveRecord :: RecordNotFound在UploadsController#秀
找不到上传与ID = 59
Couldn't find Upload with id=59
请求
参数:
{ID=>59}
下面是code这就是行搞乱了:
Here is the line of code thats messing up:
@upload = Upload.find_by_id(params[:id])
我用Rails 3.1.3。
I'm using Rails 3.1.3.
推荐答案
这竟然是用的林pressionist宝石的,我使用,因为它是迷上了我的上传节目行动,并试图执行它自己的发现之前,我有机会来处理它。
This turned out to be a problem with the Impressionist gem that I'm using as it was hooked into my Upload show action and tried to execute it's own find before I had a chance to deal with it.
这篇关于Rails的Find_by_id产生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!