Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails异常不适用于按查询查找\u_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails Rails异常不适用于按查询查找\u

Ruby on rails Rails异常不适用于按查询查找\u,ruby-on-rails,ruby,Ruby On Rails,Ruby,rails中通过查询查找\u的异常处理不起作用 代码如下: ab = User.find_by_uniq_token(params[:uniq_token]) 在以下情况下,不提出豁免: ab = User.find(:id) # is working fine... 我在应用程序控制器中有异常处理代码,如: rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found def recor

rails中通过查询查找\u的异常处理不起作用 代码如下:

  ab = User.find_by_uniq_token(params[:uniq_token])
在以下情况下,不提出豁免:

  ab = User.find(:id)  # is working fine...
我在应用程序控制器中有异常处理代码,如:

  rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found


  def record_not_found
    if current_user
      flash[:notice] = "Record not found "
      redirect_to authenticated_root_url
   else
     flash[:notice] = "Record not found ."
     redirect_to unauthenticated_root_url
     # Assuming you have a template named 'record_not_found'
   end
 end

如果未找到记录,则需要使用等效的bang(
)方法引发异常

ab = User.find_by_uniq_token!(params[:uniq_token])

ab = User.where(uniq_token: params[:uniq_token]).first!

加1,有用的问题