Turbolinks 3并呈现部分

时间:2015-04-25 17:36:56

标签: ruby-on-rails pushstate turbolinks

我对turbolinks3很兴奋(它允许你只渲染部分而不是重新加载所有的身体) 您可以从此处了解更多相关信息:https://github.com/rails/turbolinks/blob/master/CHANGELOG.md 这太棒了,但我有一个问题: 在不支持pushState的浏览器中(例如ie8 / 9),我不知道如何管理行为。 它在IE8上给我这个错误:

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

我的控制器代码是:

  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'解决方案'可能是我做的:

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

但问题是,它回复了我不需要的大量数据!(响应时间更长)所以我想找到另一个解决方案。

我如何解决这个问题? 我考虑过2个解决方案: 1)使用history.js / modernizr对旧浏览器上的pushState进行polyfill

2)找一种方法来检查请求是否由turbolinks / pjax完成...并使用条件渲染或redirect_to

  • 但我不知道如何做到这一点,因为turbolinks不会发送 像jquery-pjax
  • 这样的特定标题

有什么建议吗?我真的很感激!

PS:请不要建议我使用骨干/角度/余烬/反应,我已经知道它们(骨干),但我想尝试使用turbolinks。

1 个答案:

答案 0 :(得分:0)

你的第一直觉是正确的,IE8你需要现代化。这个问题既不是你的编码也不是涡轮链接,它是IE8。

PS:Turbolinks实际上并没有取代JS框架,如果你愿意,你可以完美地使用其中的一个。我确实将它与React和Angular一起使用。 Turbolinks只是避免重复加载相同的东西几次(感觉已经很神奇)。

相关问题