Skip to content

Instantly share code, notes, and snippets.

@ramfjord
Created June 2, 2015 01:04
Show Gist options
  • Save ramfjord/6dc9f0185a1894fe9076 to your computer and use it in GitHub Desktop.
Save ramfjord/6dc9f0185a1894fe9076 to your computer and use it in GitHub Desktop.
TypeError nil is not a symbol or string
my_table = "table_name"
conn = ActiveRecord::Base.connection
begin
conn.execute "CREATE TABLE #{my_table} (key INTEGER, val TEXT);"
klass = Class.new(ActiveRecord::Base) do
self.table_name = my_table
primary_key = "key"
default_scope { order("key DESC NULLS LAST") }
end
tmp = klass.new({key: 1})
tmp.val = "hello"
tmp.save
tmp = klass.where({key: 1}).first
tmp.val = "goodbye"
tmp.save
ensure
conn.execute "DROP TABLE #{my_table}"
end
# 2.2.2 :062 > load 'test.rb'
# TypeError: nil is not a symbol nor a string
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activemodel-4.2.1/lib/active_model/dirty.rb:181:in `attribute_was'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/attribute_methods/primary_key.rb:45:in `id_was'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/persistence.rb:513:in `_update_record'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/locking/optimistic.rb:79:in `_update_record'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/attribute_methods/dirty.rb:127:in `_update_record'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/callbacks.rb:310:in `block in _update_record'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:88:in `call'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:88:in `_run_callbacks'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:776:in `_run_update_callbacks'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/callbacks.rb:310:in `_update_record'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/timestamp.rb:70:in `_update_record'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/persistence.rb:502:in `create_or_update'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/callbacks.rb:302:in `block in create_or_update'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:88:in `call'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:88:in `_run_callbacks'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:776:in `_run_save_callbacks'
# ... 5 levels...
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/transactions.rb:347:in `block in with_transaction_returning_status'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/transactions.rb:220:in `transaction'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/transactions.rb:344:in `with_transaction_returning_status'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/transactions.rb:286:in `block in save'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/transactions.rb:301:in `rollback_active_record_state!'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.1/lib/active_record/transactions.rb:285:in `save'
# from test.rb:19:in `<top (required)>'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
# from /Users/tramfjord/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
# from (irb):62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment