jeudi 5 mai 2016

Another "Object doesn't support #inspect" Error - (Rails 3 to 4)

I say another because this error message appears all over Stack Overflow.

Other Issues

So far I've found different answers to the same error message, which doesn't apply to my case:

  1. break serialize :one, :two into two lines:

    serialize :one
    serialize :two
    
    
  2. a method of a base class is being overridden of a base class and super needs to be called

  3. a method of a like-named class is being called, instead of the intended class (related to using belongs_to), which is corrected by supplying :class_name => '::<Insert ClassName Here>' to refer to the parent ClassName.

  4. using an outdated protected_attributes gem

My Issue

Perhaps my issue is related to one of those described above, or maybe it's completely new. Here's what works and what doesn't work:

FooClassName.select(:foo_field)                           # works (returns FooClassName::ActiveRecord_Relation)
FooClassName.select(:foo_field).where(username: 'bar')    # fails (Object doesn't support #inspect)
FooClassName.select(:foo_field).where(foo_field: 'foo')   # fails (Object doesn't support #inspect)
FooClassName.select(:foo_field).where("username = 'bar'") # works (returns FooClassName::ActiveRecord_Relation)
FooClassName.select(:foo_field).where("foo_field = 'foo'") # works (returns FooClassName::ActiveRecord_Relation)

I don't think there's anything special happening in the class:

class FooClassName < ActiveRecord::Base
  establish_connection :named_connection
  self.table_name = 'name_of_view'

  # Commented out per the Rails 3 -> 4 Update guide
  #   (http://ift.tt/YwRK6e)
  # attr_accessible :foo_field, :bar_field, :username
end

So I don't know what is going on or how to debug further. Maybe it is not a permitted_param, which I have to allow as a strong param somehow?

If it helps, I am using composite_primary_keys and friendly_id gem, upgraded to the latest version I could for my version of Rails 4, but I've commented these out and the error still exists anyhow.

Thanks for any assistance.

Aucun commentaire:

Enregistrer un commentaire