在 Rails 控制器中支持使用 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.
Add this line to your application's Gemfile:
gem 'turbolinks_render'And then execute:
$ bundleBy default, render will be handled by Turbolinks if these conditions are met:
get requesttext/html content type)When these conditions are met and render is used:
when it's identical, executing elements, etc.turbolinks:load is dispatchedYou can disable turbolinks on a given request with:
render turbolinks: falseYou 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:
Rails.application.config.turbolinks_render.render_with_turbolinks_by_default = falseIn this case, to use turbolinks you should write:
render turbolinks: trueYou 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:
Rails.application.config.turbolinks_render.ignored_paths = [
'/admin'
]An example and an explanatory blog post are also available.
The gem is available as open source under the terms of the MIT License.
暂无开放 Issues,或尚未同步最近议题。