Skip to content

object method inside an Alba::Resource #319

Answered by okuramasafumi
davidgm0 asked this question in Q&A
Discussion options

You must be logged in to vote

@davidgm0 Actually there IS object method, but it points to the object given to a resource class during initialization.

# this `users` is `object` in serializer class
SomeSerializer.new(users).serialize

Alba is not meant be 100% compatible with AMS, but we'd like to make migration as easy as possible.
In this case, if object is user instead of users, it's better for migration.

One simple way is to rename a block argument from resource to object.

# This should work
attribute :id do |object|
    object.token
end

Then it's easier to do so with automation such as editor macro, just adding |object| to each end of attribute line.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by okuramasafumi
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants