Dave
Dave

Reputation: 19150

How do I include a JQuery library on only one page in my Rails app?

I’m using Rails 4.2.3. How do I include a specific Jquery library (jquery-cookie) on only one page in my application? I have this gem in my Gemfile

gem 'jquery-cookie-rails'

On my “app/views/user_objects/index.html.erb” page, I tried adding this at the top

<%= javascript_include_tag 'jquery.cookie' %>

but it results in the error “Sprockets::Rails::Helper::AssetNotPrecompiled in UserObjects#index”.

Upvotes: 0

Views: 364

Answers (1)

Albert Paul
Albert Paul

Reputation: 1208

Use,

<%= javascript_include_tag 'js.cookie' %>

Because jquery.cookie is superseded by js.cookie.

If that didn't work use js.cookie gem,

https://github.com/freego/js_cookie_rails

gem 'js_cookie_rails'

<%= javascript_include_tag 'js.cookie' %>

Upvotes: 2

Related Questions