百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

turbolinks_render

> 后端框架
开源

在 Rails 控制器中支持使用 Turbolinks 进行 `render`

168 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

在 Rails 控制器中支持使用 Turbolinks 进行 `render`

turbolinks_render

Use render in your Rails controllers and handle the response with Turbolinks.

Turbolinks supports redirect_to out of the box. But render is not supported and you have to use workarounds for common things like dealing with forms. This gem aims to fix that.

I think Turbolinks/Rails should handle this officially. If you agree you can vote for this idea.

Installation

Add this line to your application's Gemfile:

ruby
gem 'turbolinks_render'

And then execute:

bash
$ bundle

Usage

By default, render will be handled by Turbolinks if these conditions are met:

  • It's an ajax request
  • It's not a get request
  • It generates an html response (text/html content type)

When these conditions are met and render is used:

  • The page content is replaced with the rendered content with Javascript. It uses Turbolinks to do this replacement, so it is pretty smart about keeping the when it's identical, executing elements, etc.
  • An event turbolinks:load is dispatched

You can disable turbolinks on a given request with:

ruby
render turbolinks: false

Configuration

You can invert the default behavior: never use turbolinks for rendering unless explicitly indicated. Create a file config/initializers/turbolinks_render.rb and toggle turbolinks_render.render_with_turbolinks_by_default:

ruby
Rails.application.config.turbolinks_render.render_with_turbolinks_by_default = false

In this case, to use turbolinks you should write:

ruby
render turbolinks: true

You can also ignore specific paths in your application. This can be useful if you're using an engine and don't have access to its code to change the render calls. For instance, to ignore anything that starts with /admin:

ruby
Rails.application.config.turbolinks_render.ignored_paths = [
  '/admin'
]

Implementation notes

  • It configures a rack middleware that intercept requests and modify responses when the expected conditions are met.
  • It uses some internal Turbolinks classes to perform the rendering. This makes the DOM-update logic very smart but it could introduce problems with future Turbolink versions , since this does not belong to its public API. I'll do my best to keep things up to date.

Example

An example and an explanatory blog post are also available.

Credits

  • Original implementation based on this idea by @nerdcave.

License

The gem is available as open source under the terms of the MIT License.

Issues· 13 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyrailsturbolinks

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架