unpoly-rails
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUnpoly Rails
Unpoly Rails
The gem integrates Unpoly's server protocol into
Rails, exposing helper methods in controllers, views, and helpers.
unpoly-railsGem: — tracks Unpoly 3.x
unpoly-railsunpoly-railsGem: — 适配Unpoly 3.x版本
unpoly-railsInstallation
安装
ruby
undefinedruby
undefinedGemfile
Gemfile
gem 'unpoly-rails'
undefinedgem 'unpoly-rails'
undefinedFrontend assets via Asset Pipeline
通过Asset Pipeline引入前端资源
js
// application.js
//= require unpolycss
/* application.css
*= require unpoly
*/js
// application.js
//= require unpolycss
/* application.css
*= require unpoly
*/Frontend assets via npm (esbuild, Webpacker, etc.)
通过npm引入前端资源(esbuild、Webpacker等)
js
import 'unpoly/unpoly.js'
import 'unpoly/unpoly.css'js
import 'unpoly/unpoly.js'
import 'unpoly/unpoly.css'Quick reference
快速参考
| Helper | Purpose |
|---|---|
| Is this an Unpoly fragment request? |
| CSS selector being updated (success) |
| Override the render target |
| Is this selector targeted? |
| CSS selector targeted for failed responses |
| Is selector targeted for success or failure? |
| Is this a form validation request? |
| Field names that triggered validation |
| Layer mode: |
| Is the targeted layer an overlay? |
| Is the targeted layer the root layer? |
| Accept the current overlay |
| Dismiss the current overlay |
| Request frontend to open a new overlay |
| Layer context hash |
| Alias for |
| Emit event on |
| Emit event on the targeted layer |
| Expire the client-side cache |
| Evict entries from the client-side cache |
| Set document title from server |
| CSP-safe inline callback with nonce |
| Render empty 204 response |
| Read Unpoly headers without setting Vary |
| 助手方法 | 用途 |
|---|---|
| 判断是否为Unpoly片段请求? |
| 待更新的CSS选择器(成功响应时) |
| 覆盖渲染目标 |
| 该选择器是否为目标? |
| 失败响应时的目标CSS选择器 |
| 该选择器是否为成功或失败响应的目标? |
| 是否为表单验证请求? |
| 触发验证的字段名称 |
| 层级模式: |
| 目标层级是否为浮层? |
| 目标层级是否为根层级? |
| 确认当前浮层 |
| 关闭当前浮层 |
| 请求前端打开新的浮层 |
| 层级上下文哈希 |
| |
| 更新后在 |
| 在目标层级上触发事件 |
| 过期客户端缓存 |
| 从客户端缓存中移除条目 |
| 从服务器端设置文档标题 |
| 带随机数的CSP安全内联回调 |
| 渲染空的204响应 |
| 读取Unpoly请求头而不设置Vary头 |
Reference files
参考文档
Load when the user's question covers that topic:
- server-helpers.md — Full API reference: request inspection, response control, layer API, validation, events, cache control, context, CSP callbacks, failed forms, Vary headers, conditional GETs, common Rails patterns
- rails-integration.md — View helper syntax (,
link_to,form_with, field helpers), Turbo coexistence (disabling Turbo Drive in Rails 7+), CSP setup withbutton_to, global follow-all configcsp_meta_tag - patterns.md — End-to-end Rails patterns: drawer overlay helper, event-driven subinteractions (/
up-accept-event), create related record inline + validate parent form, authorization overlay vs root layerup-dismiss-event
当用户的问题涉及以下主题时加载:
- server-helpers.md — 完整API参考:请求检查、响应控制、层级API、验证、事件、缓存控制、上下文、CSP回调、失败表单、Vary头、条件GET、常见Rails模式
- rails-integration.md — 视图助手语法(,
link_to,form_with, 字段助手)、与Turbo共存(在Rails 7+中禁用Turbo Drive)、使用button_to配置CSP、全局follow-all配置csp_meta_tag - patterns.md — 端到端Rails模式:抽屉浮层助手、事件驱动的子交互(/
up-accept-event)、内联创建关联记录+验证父表单、授权浮层 vs 根层级up-dismiss-event