Module: InertiaJb
- Defined in:
- lib/inertia_jb.rb,
lib/inertia_jb/helper.rb,
lib/inertia_jb/handler.rb,
lib/inertia_jb/railtie.rb,
lib/inertia_jb/version.rb,
lib/inertia_jb/renderer.rb,
lib/inertia_jb/controller.rb
Overview
InertiaJb lets you declare Inertia.js props for your Rails frontend components inside view templates, using plain Ruby Hashes powered by the jb renderer.
A *.html.inertia template is Ruby code whose last expression is a Hash of
props. That Hash is handed straight to InertiaRails::Renderer, so every
Inertia protocol feature (partial reloads, optional/always/deferred props,
merging, shared data, key transforms) works out of the box.
Defined Under Namespace
Modules: Controller, Helper, Renderer Classes: Handler, Railtie
Constant Summary collapse
- VERSION =
"0.3.1"
Class Method Summary collapse
-
.bind_to_view(view, block) ⇒ Object
Binds a lazy-prop block to the view that declared it, so the block evaluates in the same view context as an eager prop.
Class Method Details
.bind_to_view(view, block) ⇒ Object
Binds a lazy-prop block to the view that declared it, so the block evaluates in the same view context as an eager prop.
Eager props are evaluated while the .inertia template renders, so their
render(partial: ...) is the view helper — it returns jb data and never
touches response_body. Lazy props (+defer+/+optional+/+always+/...) are
different: inertia-rails resolves them later via
controller.instance_exec(&block), i.e. in controller context, where the
same render(partial: ...) binds to +ActionController+'s render and
assigns response_body. inertia-rails then performs its own
render(json:), and the already-set response_body raises
AbstractController::DoubleRenderError.
Wrapping the block in view.instance_exec keeps every block — eager or
lazy — running against the view, so render behaves identically everywhere.
Controller-exposed helpers still work in the view (e.g. policy_scope,
current_user via Pundit/Devise +helper_method+s); the only controller-only
call that does not carry over is render_to_string — use +render(partial:,
formats: [:html])+ instead, which returns the same String in a view.
76 77 78 79 80 |
# File 'lib/inertia_jb/helper.rb', line 76 def self.bind_to_view(view, block) return block if block.nil? proc { view.instance_exec(&block) } end |