You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's kind of confusing, but in Alba, Resource class is responsible for converting objects into a Hash, and Serializer is responsible for dumping actual JSON string with some modification like key and metadata.
For now, please take a look at test directory and there are many working examples. I'll add more examples later.
For pagination, Alba doesn't provide a support for pagy gem or other gems. For now, you can do something like this:
# Assume that IssueResource includes Alba::Resourcedefindex@pagy,@issues=pagy(Issue.all)pagy=@pagy# This is dirty trick to pass data to `metadata` blockpagination_metadata_method=method(:pagy_metadata)with=procdometadata:paginationdopagination_metadata_method.call(pagy,{url: true})endendrenderjson: IssueResource.new(@issues).serialize(with: with)end
Because Alba doesn't provide support for passing extra data to metadata block (I'm considering what is the best way to do so), we must do some dirty stuff here.
First, serializer part must be defined in a Proc. Then, pagy must be present as local variable. Finally, you must use method method to call pagination method in metadata block.
I surely know that this is not how it should be, so I'll improve support for pagination soon.
Hi @okuramasafumi,
Thanks for your comments
Sure, I'll have a depper look at your examples and code
Keep the good work, Alba looks as a good fit for me
Hi,
I can't figure out how to implement the serializer class
I understand the ressource, but how look like the Serializer class ?
Here is what my serializer from AMS
and in controller
I would like to use with metadata pagination Pagy
How would you advise me using Alba in this case ?
Thanks
The text was updated successfully, but these errors were encountered: