Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Have any way to return on has_many :roles a array instead of object?
has_many :roles
class UserSerializer < ActiveModel::Serializer attributes :id, :name, :nickname, :image, :roles has_many :roles end
Thanks.
You can build your own custom methods in the serializer and use those as attributes
class UserSerializer < ActiveModel::Serializer attributes :role_names def role_names object.roles.map(&:name) end end
Add a comment
You usually use includes for that. I'm not that familiar with using serializers though.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.