Rails 3 - How to Not to Error if no record is found

Viewed 15773

In my permissions controller, I use Active record to look for a permission:

@permission = Permission.find(params[:user_id])

If this returns a result I then look up the permission.name And pass this to my controller.

Problem is sometimes this does returna result, othertimes it does not. When it does not, it errors. How can I prevent that from occuring?

Use Case: 1. If the user does have a permission record, show it and let the user change it 2. If not, show they don't have a permission record and allow the user to set a permission.

Thanks

5 Answers
Related