okuramasafumi / alba

Alba is a JSON serializer for Ruby, JRuby and TruffleRuby.
https://okuramasafumi.github.io/alba/
MIT License
934 stars 43 forks source link

Rails controller integration #368

Closed okuramasafumi closed 3 months ago

okuramasafumi commented 5 months ago

Is your feature request related to a problem? Please describe.

In Rails controller, we still need to integrate manually with something like render json: FooResource.new(foo).

Describe the solution you'd like

For example:

class FoosController < ApplicationController
  def show
    foo = Foo.find(params[:id])
    render_serialized_json foo
  end
end

Describe alternatives you've considered

class FoosController < ApplicationController
  def show
    foo = Foo.find(params[:id])
    render json: serialize(foo)
  end
end

Additional context

In a book, Layered Design for Ruby on Rails Applications, the author (@palkan) uses a custom integration with Rails, and I see it convenient.