-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support json builders for generating props #133
Comments
Hi! Author of props_template here! props_template also has support for deferred props via the You can also extend it and make it specific for inertia using the extension manager here |
This is a super cool idea, I might hack around on it this weekend. I really like the pattern. |
@BrandonShar here's a quick snippet I posted in the Discord (just in case): class InertiaExampleController < ApplicationController
def inertia_view_assigns
template = lookup_context.find_template(action_name, controller_path)
json = JbuilderTemplate.new(self)
binding.eval template.source
json.attributes!
end
def index
# or set config.default_render: true
render(inertia: true)
end
end But to be honest, I'd love to introduce a plugin system here, so we could support different serializers (and allow users to hook into the process as well). |
@skryukov are there any analogous plugin systems you have in mind we could use for inspiration? |
@skryukov @BrandonShar Brilliant idea. But it seems that if you try to use The following code works, but really weird. def inertia_view_assigns
return {} unless lookup_context.exists?(action_name, controller_path)
JSON.parse(render_to_string(formats: [:json]))
end |
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.
The text was updated successfully, but these errors were encountered: