I don't think @environment will ever be nil since KTEnvironment.find doesn't return nil. Might want to make the previous line use find_by_id instead.