如何在我的Rails应用程序中的一个页面上包含一个JQuery库?

时间:2016-03-01 15:56:50

标签: javascript jquery ruby-on-rails include js-cookie

我正在使用Rails 4.2.3。如何在我的应用程序中的一个页面上包含特定的Jquery库(jquery-cookie)?我的Gemfile中有这个gem

gem 'jquery-cookie-rails'

在我的“app / views / user_objects / index.html.erb”页面上,我尝试在顶部添加此内容

<%= javascript_include_tag 'jquery.cookie' %>

但它导致错误“Sprockets :: Rails :: Helper :: AssetNotPrecompiled in UserObjects #index”。

1 个答案:

答案 0 :(得分:2)

使用,

<%= javascript_include_tag 'js.cookie' %>

因为jquery.cookie被js.cookie取代。

如果不起作用,请使用js.cookie gem,

https://github.com/freego/js_cookie_rails

gem 'js_cookie_rails'

<%= javascript_include_tag 'js.cookie' %>
相关问题