Successful safe constantize

suggest change

User is an ActiveRecord or Mongoid class. Replace User with any Rails class in your project (even something like Integer or Array)

my_string = "User" # Capitalized string
  # => 'User'
my_constant = my_string.safe_constantize
  # => User
my_constant.all.count
  # => 18

my_string = "Array"
  # => 'Array'
my_constant = my_string.safe_constantize
  # => Array
my_constant.new(4)
  # => [nil, nil, nil, nil]

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Safe constantize:
* Successful safe constantize

Table Of Contents
3 Views
19 Caching
22 Safe constantize
23 Rails 5
25 Mongoid
26 Gems
55 CSV