TypeError: no implicit conversion of nil into String. utils.rb:24:in `quote_ident’

I made rake task.
My rails app is running without problems.

Code

namespace :i18n_master do
  task check: :environment do
    read_model
    models = ActiveRecord::Base.descendants.map do |model|
      next if model.name.nil?
      model2hash(model)
    end

    p models
  end

  def model2hash(model)
    return Hash[model.name, model.column_names]
  end

  def read_model
    Dir[Rails.root.to_s + '/app/models/**/*.rb'].each do |file|
      begin
        require file
      rescue
      end
    end
  end
end

Error

rake aborted!
TypeError: no implicit conversion of nil into String
ror_app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/utils.rb:24:in `quote_ident'
ror_app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/utils.rb:24:in `quoted'
ror_app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/quoting.rb:31:in `quote_table_name'
ror_app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:742:in `column_definitions'
ror_app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/schema_statements.rb:186:in `columns'
ror_app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/schema_cache.rb:43:in `columns'
ror_app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/attributes.rb:93:in `columns'
ror_app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/model_schema.rb:260:in `column_names'
ror_app/lib/tasks/i18n_master.rake:13:in `model2hash'
ror_app/lib/tasks/i18n_master.rake:6:in `block (3 levels) in <top (required)>'
ror_app/lib/tasks/i18n_master.rake:4:in `map'
ror_app/lib/tasks/i18n_master.rake:4:in `block (2 levels) in <top (required)>'

I read this

Rails 4.0.0 – Got “no implicit conversion of nil into String”

the above problems is gem for sqlite3.
so I think my problem is gem for postgresql.

But My rails app is running without problems.
And I use bundle.

% bundle pristine
Could not find command "pristine".

Why

Why TypeError: no implicit conversion of nil into String is occur in utils.rb:24:in quote_ident'

How to fix it?


Source: ruby

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.