Turbolinks 3 and do partial

I am delighted with turbolinks3 (it allows you to display only partial and not reboot the whole body) You can learn more about it from here: https://github.com/rails/turbolinks/blob/master/CHANGELOG.md It's awesome, but me problem: In browsers that do not support pushState (ie8 / 9 example), I do not know how to control the behavior. This gives me this error in IE8:

Could not set the innerHTML property. Invalid target element for this operation. 

My controller code:

  def create @post = Post.find(params[:post_id]) if @post.comments.create(comment_params) render '_comment', change: [:comments, :super_test], layout: false, :locals => { comment: @post.comments.last } else render json:'error' end end 

A β€œsolution” could be:

 redirect_to @post, change: [:comments, :super_test] 

But then the problem is that it responds with a lot of data that I do not need! (and response time is longer). So again I want to find another solution.

How can I solve this problem? I thought of 2 solutions: 1) Use history.js / modernizr for polyfill pushState in older browsers

2) Find a way to check if the turbolinks / pjax request is running or not ... and use conditional rendering or redirect_to

  • But I do not know how I can do this because turbolinks does not send a specific header, for example jquery-pjax

Any suggestions? I really appreciate that!

PS: Please do not offer me the spine / angular / ember / to respond, I already know them (the spine), but I want to try turbolinks.

+6
source share
1 answer

Your first instinct is right, with IE8 you will need an upgrade. the problem is not that you are not coding or turbolinks here, it is IE8.

PS: Turbolinks does not actually replace JS frameworks, you can use it perfectly with one of them if you want. I used it with React and Angular. Turbolinks simply avoids reloading the same thing several times (which already feels magic).

0
source

Source: https://habr.com/ru/post/985959/


All Articles