【问题标题】:How to render html.erb conditionally from javascript (WebGL check)如何从 javascript 有条件地呈现 html.erb(WebGL 检查)
【发布时间】:2014-01-29 04:10:22
【问题描述】:

我想根据 WebGL 支持决定在 Rails 应用程序中呈现哪些内容。

我知道我可以从 JS 中检查 WebGL

 if (!window.WebGLRenderingContext) {

     return;   }

但是我如何使用它来决定在 html.erb 中呈现什么?

我想要类似的东西

 if (!window.WebGLRenderingContext) {

       // Use some <%= rails_helper %>

        }else{

    // <%= use_another_rails_helper %>
 }

【问题讨论】:

    标签: javascript ruby-on-rails ruby-on-rails-3 erb


    【解决方案1】:

    这是您要找的吗?

     if(!window.WebGLRenderingContext) {
       $("#div_id").html(<%= rails_helper %>);
      }
    else {
       $("#div_id").html(<%= use_another_rails_helper %>);
     }
    

    【讨论】:

    • 是的,这实际上是我最终做的事情。我使用 js.erb 并使用 .html() 和 .insertAfter() 从那里渲染部分
    猜你喜欢
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    • 2021-10-14
    • 1970-01-01
    • 2014-11-08
    • 2019-10-03
    相关资源
    最近更新 更多