Take the 2-minute tour ×

When o try verify in my helper if my database have the record this stop on the verifier whit this error:

ActiveRecord::RecordNotFound in FinancesController#index

Couldn't find Place with id=5

Im using this helper:

  def get_acc_name(acc_id)
    @var = Place.find(acc_id)
    if @var.kind_of?(Array)
    @var = @var.place 
    @var = "(Deletado)"
    return @var

The problem is the script stop on the first line and font make a if else, i dont know how i solve this please

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You can use where instead of find. find raises exception if a record is not found. So, use this instead:

@var = Place.where(:id => acc_id).first


@var = Place.find_by_id(acc_id)

They will not raise exception. :)

share|improve this answer
Thanks im solver using the find_by_id and the verify a simple if @var, thanks for help. –  overallduka Feb 15 '13 at 0:17
You are welcome :) –  Manoj Monga Feb 15 '13 at 2:52
add comment

Your Answer


