0.0
No commit activity in last 3 years
No release in over 3 years
Raise error, print warning log, return nil when call find by nil or Fixnum.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 4.2.0
 Project Readme

WhereIsNil

Gem Version Code Climate Test Coverage Circle CI

find_by(nil) always returns first record. (Issue #14867 ยท rails/rails)
WhereIsNil gives notice when invoke find_by(nil) or find_by(Fixnum).

Requirement

  • Rails 4.2

Installation

# Gemfile
gem 'where_is_nil'

Usage

$ rails c
> User.find_by(id: 1)
=> #<User id: 1>

> User.find_by(nil)
WhereIsNil::FindByNil: Why do you find by nil? Did you mean `find_by(id: nil)`?

> User.find_by(1)
WhereIsNil::FindByNil: Why do you find by 1? Did you mean `find_by(id: 1)`?

Configuration

# config/initializers/where_is_nil.rb

# Enable where_is_nil features.
WhereIsNil.config.enabled = true

# Print error messages to the Rails logger.
WhereIsNil.config.warning_log = true

# Raise `WhereIsNil::FindByNil` errors.
WhereIsNil.config.raise_error = true

# Return nil with `find_by`, Raise `ActiveRecord::NotFound` with `find_by!`.
WhereIsNil.config.not_found = false

Licence

This project rocks and uses MIT-LICENSE.

Author

@tnantoka