Ruby on Rails: How to check if the Model Exists
Since defined?
is problematic (see @Jiggneshh Gohel's comment), perhaps you can check the filenames in the models
dir.
files = Dir[Rails.root + 'app/models/*.rb']
models = files.map{ |m| File.basename(m, '.rb').camelize }
models.include? "User" => true
defined? ModelName
will return "constant" if model defined.