fabrik42/acts_as_api

When table has column 'model_name' - unable to render JSON for object

adamkleingit opened this issue · 1 comments

My Active Record model has a column called 'model_name'
acts_as_api fails to render it well because of rendering.rb, line 50:

' elsif api_model.respond_to?(:model_name) '

the api_root_name checks 'respond_to?(:model_name)' which returns true, because my model has an attribute 'model_name', and so the root is wrong (or nil which results in exception).

is this option for rendering ActiveRecord classes?

My suggestion:
' elsif api_model < ActiveRecord::Base || (mongoid test) '

or

' elsif api_model.respond_to?(:model_name) && api_model.is_a? Class '

Sorry but by having a column called model_name you are overwriting the public ActiveModel method model_name (see http://api.rubyonrails.org/classes/ActiveModel/Naming.html#method-i-model_name)

I understand that you need a workaround for your specific case, but I don't want to introduce this in the lib, especially because model_name is also used by vanilla classes to enable acts_as_api (see: https://github.com/fabrik42/acts_as_api/wiki/Declaring-api-templates-for-any-class%21-%28no-orms%29)