【问题标题】:insert specifics js in the header of some pages - active admin在某些页面的标题中插入细节 js - 活动管理员
【发布时间】:2012-10-09 22:18:07
【问题描述】:

我使用活动管理员,在我的应用中,必须在特定页面(不是全部)中加载不同的 .js。

按照这个主题Best way to add page specific javascript in a Rails 3 app? 看起来很简单,但是活动管理员中的布局已编译。

我使用了一种解决方法来覆盖页脚:

    class ActiveAdmin::Views::Pages::Base < Arbre::HTML::Document
 private
  # Renders the content for the footer
  def build_footer
    div :id => "footer" do
      para "Copyright &copy; #{Date.today.year.to_s}- All rights reserved ".html_safe
    end
  end
end

如何在某些页面的页眉中添加一些 .js?如何解决? (如果可能的话,使用“yield :head”或类似的东西,所以我可以从任何地方更容易地调用它;))

编辑注意:我想要包含的 js 呈现一个 highcharts

【问题讨论】:

    标签: jquery ruby-on-rails highcharts activeadmin head


    【解决方案1】:

    我正在使用 ActiveAdmin 0.5.0 的主分支(截至 2012 年 11 月 23 日),并且有一个 Arbre builder 方法 within 对我有用。

    show do 
       within @head do
          script :src => javascript_path('somefile.js'), :type => "text/javascript"
       end
    end 
    

    您可以在ActiveAdmin::Views::Pages::Base#build_active_admin_head 中查看其使用示例。

    希望这会有所帮助。

    【讨论】:

    • 谢谢,我会在接下来的几天里尝试,你有任何关于“Arbre builder”如何工作的网址吗? (或者你在哪里找到这些信息)
    • 我想我刚刚在 Arbre 源代码中搜索了“javascript”之类的内容。
    【解决方案2】:

    我找到了一个“替代”解决方案,基本的解决方案:只需将带有 jquery 标签 $(document).ready(...) 的脚本插入到 html 正文中(但会降低性能和干编码)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多