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
The idea is that if you are using the “first param is the id” version of find, you know exactly what you are looking for, and if it isn’t there, thats a problem. If you use one of the more generic finder syntaxes (like find_by_field_name), the assumption is that if it isn’t there, that is an acceptable situation so just return nil.