Module: Turbolinks::Redirection
- Included in:
- Controller
- Defined in:
- lib/turbolinks/redirection.rb
Overview
Provides a means of using Turbolinks to perform renders and redirects. The server will respond with a JavaScript call to Turbolinks.visit/replace().
Constant Summary collapse
- MUTATION_MODES =
[:change, :append, :prepend].freeze
Instance Method Summary collapse
- #redirect_to(url = {}, response_status = {}) ⇒ Object
- #redirect_via_turbolinks_to(url = {}, response_status = {}) ⇒ Object
- #render(*args, &block) ⇒ Object
Instance Method Details
#redirect_to(url = {}, response_status = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/turbolinks/redirection.rb', line 7 def redirect_to(url = {}, response_status = {}) turbolinks, = (response_status) turbolinks = (request.xhr? && (.size > 0 || !request.get?)) if turbolinks.nil? if turbolinks response.content_type = Mime[:js] end return_value = super(url, response_status) if turbolinks self.status = 200 self.response_body = "Turbolinks.visit('#{location}'#{()});" end return_value end |
#redirect_via_turbolinks_to(url = {}, response_status = {}) ⇒ Object
45 46 47 48 |
# File 'lib/turbolinks/redirection.rb', line 45 def redirect_via_turbolinks_to(url = {}, response_status = {}) ActiveSupport::Deprecation.warn("`redirect_via_turbolinks_to` is deprecated and will be removed in Turbolinks 3.1. Use redirect_to(url, turbolinks: true) instead.") redirect_to(url, response_status.merge!(turbolinks: true)) end |
#render(*args, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/turbolinks/redirection.rb', line 25 def render(*args, &block) = args. turbolinks, = () turbolinks = (request.xhr? && .size > 0) if turbolinks.nil? if turbolinks response.content_type = Mime[:js] = _normalize_render(*args, , &block) body = render_to_body() self.status = 200 self.response_body = "Turbolinks.replace('#{view_context.j(body)}'#{()});" else super(*args, , &block) end self.response_body end |