I've tried to rescue from RecordNotFound error in controller like this:
  def create_user_role
    authorize User
    role = params[:user][:rolify_role].to_sym
    resource_type = params[:user][:resource_type]
    resource_id = params[:user][:id]
    # Catch RecordNotFound doesn't work
    begin
      resource = nil
      resource = resource_type.constantize.find(resource_id) if RolifyRoles.available_resources.include?(resource_type) && resource_id.present?
    rescue ActiveRecord::RecordNotFound => e
      format.html { render :show }
      flash[:error] = e.message
    end
  end
And when the resource_type.constantize.find(resource_id) cannot find the record, its doesn't caught by the rescue block.
 Completed 500 Internal Server Error in 46ms (ActiveRecord: 3.2ms)
 ActiveRecord::RecordNotFound - Couldn't find RequestComment with 'id'=1:
 app/controllers/users_controller.rb:58:in `create_user_role'
I've tried to rescue with StandardError or even with Exception and result was the same.
Where is the problem?
I am also calling a method from my module which raise some exceptions, which also aren't handled.
Backtrace:
07:23:29 web.1     | Started POST "/users/kru0096/create_user_role" for 10.0.131.29 at 2018-06-13 07:23:29 +0200
07:23:39 web.1     | Processing by UsersController#create_user_role as HTML
07:23:39 web.1     |   Parameters: {"utf8"=>"✓", "authenticity_token"=>"5kN6MuoP4YntbTvL5cTDPuCZypDdO
o1KPcvIu8dJ6otX0aYPwuWg64/TTTgDe6DRXn6wCs1KvgT9xjkr9g/dyA==", "user"=>{"rolify_role"=>"hoac", "resource_type"=>"RequestComment", "id"=>"1"}, "commit"=>"", "id"=>"kru0096"}
07:23:39 web.1     |   User Load (0.3ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
07:23:39 web.1     |   User Load (0.3ms)  SELECT  `users`.* FROM `users` WHERE `users`.`login` = 'kru0096' LIMIT 1
07:23:39 web.1     |   RequestComment Load (0.3ms)  SELECT  `request_comments`.* FROM `request_comments` WHERE `request_comments`.`id` = 1 LIMIT 1
07:23:39 web.1     | Completed 500 Internal Server Error in 41ms (ActiveRecord: 6.5ms)
07:23:39 web.1     | 
07:23:39 web.1     | 
07:23:39 web.1     | 
07:23:39 web.1     | ActiveRecord::RecordNotFound - Couldn't find RequestComment with 'id'=1:
07:23:39 web.1     |   app/controllers/users_controller.rb:92:in `create_user_role'
07:23:39 web.1     | 
 
    