From the Rails way of doing things writing props in controllers feels a little out of place, Consider this example from PingCRM
json.data(paged_contacts) do |contact|
json.(contact, :id, :name, :phone, :city, :deleted_at)
if contact.organization
json.organization(contact.organization, :name)
end
end
I imagine in a more complicated app, this logic will start growing into multi line conditions making controllers fat.
It would be great if building props json can be pushed to view layer by leveraging existing robust engines like Jbuilder, props_template etc. instead.
For example
class EventsController < ApplicationController
use_inertia_view_props :jbuilder # <- tell inertia to use jbuilder templating engine
def index
@events = Event.all
# props -> app/views/events/index.json.jbuilder
end
end
And
class EventsController < ApplicationController
def index
@events = Event.all
render inertia: 'Events/Index', template: 'index'
# props -> app/views/events/index.json.jbuilder
end
end
This would simplify controllers and unlock capabilities of json builder engines for better usability.
Moreover, I see a possibility of projects that already use json builders for sending data to frontends can progressively adapt Inertia by reusing their existing templates.
From the Rails way of doing things writing props in controllers feels a little out of place, Consider this example from PingCRM
I imagine in a more complicated app, this logic will start growing into multi line conditions making controllers fat.
It would be great if building props json can be pushed to view layer by leveraging existing robust engines like Jbuilder, props_template etc. instead.
For example
And
This would simplify controllers and unlock capabilities of json builder engines for better usability.
Moreover, I see a possibility of projects that already use json builders for sending data to frontends can progressively adapt Inertia by reusing their existing templates.