docs / when it breaks
Server functions and queries
Errors when React calls Rails: a useQuery call with the wrong parameters, a signed reference that does not verify, an upload over the limit, a query that needs current_user, and a server action that raised.
request time · HTTP 400 / 413 / 500ruact 0.0.22
When you finish
- which call-side mistakes come back as a 400, and what the body says
- why a signed reference demands a purpose and an expiry
- where a server action that raised shows up
A server function or a useQuery call is a request from React to a Rails action. When it fails, React gets a status and a JSON body with the message; the messages are below. See Server functions for the calls themselves. Values the gem fills from your app are in angle brackets.
useQuery parameters
Section titled “useQuery parameters”A query method’s keyword arguments are its parameters. The call is checked against them before the method runs, and a mismatch is an HTTP 400.
ruact query :search_posts is missing required parameter(s) :term.ruact query :search_posts received unknown parameter :q — it matches no keyword argument of the query method.ruact query :search_posts parameter :filters must be a string, number, boolean, or null — arrays and objects are rejected (got Hash).A query that calls current_user
Section titled “A query that calls current_user”ruact: the query dispatch controller (inheriting ApplicationController, via Ruact.config.query_parent_controller) does not define `current_user`. Define it on the parent controller, or point `query_parent_controller` at a controller that does.Fix. Queries run in a controller ruact draws, which inherits Ruact.config.query_parent_controller. Point that setting at the controller that defines current_user, or define it there.
Signed references
Section titled “Signed references”A signed reference is a token for a record that React can hold and send back, scoped to one purpose and, by default, to a time.
Signed reference could not be verified for purpose :edit_post (it may be tampered, expired, or scoped to a different purpose).Why. The token was changed, its time ran out, or it was signed for another purpose than the one it is resolved with.
Ruact signed references require a purpose: pass `for:` (a Symbol/String scoping the token to one use-site) or set `Ruact.config.signed_global_id_default_purpose`. Refusing to sign or resolve an unscoped reference.Ruact.signed_global_id requires an expiry: pass `expires_in:` (an ActiveSupport::Duration like `15.minutes`, or an explicit `nil` to deliberately mint a non-expiring token) or set `Ruact.config.signed_global_id_default_expires_in`. Refusing to silently mint a non-expiring reference.Fix. Pass both where you sign: Ruact.signed_global_id(post, for: :edit_post, expires_in: 15.minutes), and the same for: where you resolve it. Or set the defaults in config/initializers/ruact.rb.
Uploads
Section titled “Uploads”Upload exceeded the configured size limit (received_bytes=<bytes>, limit_bytes=<bytes>)Fix. Raise config.max_upload_bytes, or set it to nil to turn off ruact’s own check and leave the limit to your server.
A server action that raised
Section titled “A server action that raised”Any other error inside the action is the action’s own. Its status follows the error: ActiveRecord::RecordInvalid is a 422, a bad authenticity token a 403, anything else a 500. The log has it in every environment, followed by the backtrace:
[ruact] server action :publish failed — NoMethodError: undefined method 'publish!' for nil