Skip to content
This repository has been archived by the owner on Jul 28, 2018. It is now read-only.

Commit

Permalink
Merge pull request #510 from Thibaut/render
Browse files Browse the repository at this point in the history
Render XHR+GET requests with turbolinks by default
  • Loading branch information
rafaelfranca committed Apr 21, 2015
2 parents 8815c75 + f387452 commit 5f4c27d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ redirect_to path, flush: true
```

```ruby
# Render with Turbolinks when the request is XHR and not GET.
# Render with Turbolinks when the request is XHR.
# Refresh any `data-turbolinks-temporary` nodes and nodes with `id` matching `new_comment`.
render view, change: 'new_comment'

Expand Down
2 changes: 1 addition & 1 deletion lib/turbolinks/redirection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def render(*args, &block)

super(*args, render_options, &block)

if turbolinks || (turbolinks != false && options.size > 0 && request.xhr? && !request.get?)
if turbolinks || (turbolinks != false && options.size > 0 && request.xhr?)
_perform_turbolinks_response "Turbolinks.replace('#{view_context.j(response.body)}'#{_turbolinks_js_options(options)});"
end

Expand Down
10 changes: 8 additions & 2 deletions test/turbolinks/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,18 @@ def test_render_via_xhr_and_delete_with_multiple_keep_option_renders_via_turboli
assert_turbolinks_replace 'content', "{ keep: ['foo', 'bar'] }"
end

def test_render_via_xhr_and_get_with_change_option_does_normal_render
def test_simple_render_via_xhr_and_get_does_normal_render
@request.env['HTTP_ACCEPT'] = Mime::HTML
xhr :get, :render_with_single_change_option
xhr :get, :simple_render
assert_normal_render 'content'
end

def test_render_via_xhr_and_get_with_change_option_renders_via_turbolinks
@request.env['HTTP_ACCEPT'] = Mime::HTML
xhr :get, :render_with_single_change_option
assert_turbolinks_replace 'content', "{ change: ['foo'] }"
end

def test_render_via_post_and_not_xhr_with_keep_option_does_normal_render
post :render_with_multiple_keep_option
assert_normal_render 'content'
Expand Down

0 comments on commit 5f4c27d

Please sign in to comment.