Instead of doing this, you can implement as_json on Project and then have your controller respond_to json.