【问题标题】:How do I get the jquery-cookie plugin to work with Rails 5?如何让 jquery-cookie 插件与 Rails 5 一起使用?
【发布时间】:2017-05-20 06:00:16
【问题描述】:

我想使用Rails 5.0.1,并且我的应用程序中还需要 jQuery cookie 插件。我已将其包含在我的Gemfile

gem 'jquery-cookie-rails'

但是自从更改了我的Rails dependency to 5.0.1 后,我现在在运行bundle install 时收到此错误...

localhost:myproject davea$ bundle install
Your Gemfile lists the gem pg (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of one of them later.
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies...
Bundler could not find compatible versions for gem "railties":
  In snapshot (Gemfile.lock):
    railties (= 5.0.1)

  In Gemfile:
    coffee-rails was resolved to 4.2.1, which depends on
      railties (< 5.2.x, >= 4.0.0)

    jquery-cookie-rails was resolved to 0.1.1, which depends on
      railties (< 5.0, >= 3.2.0)

    jquery-rails was resolved to 4.2.1, which depends on
      railties (>= 4.2.0)

    jquery-turbolinks was resolved to 2.1.0, which depends on
      railties (>= 3.1.0)

    jquery-ui-rails was resolved to 6.0.1, which depends on
      railties (>= 3.2.16)

    rails (~> 5.0.1) was resolved to 5.0.1, which depends on
      railties (= 5.0.1)

    sass-rails was resolved to 5.0.6, which depends on
      railties (< 6, >= 4.0.0)

    web-console was resolved to 3.4.0, which depends on
      railties (>= 5.0)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

我怎样才能把蛋糕也吃掉?我想使用最新版本的 Rails,也想使用 jQuery-cookie。我该怎么做?

【问题讨论】:

  • 当然,您的意思是“我怎么能把我的饼干也吃掉?”。

标签: jquery ruby-on-rails rubygems ruby-on-rails-5 jquery-cookie


【解决方案1】:

尝试使用gem install jquery-cookie-rails --version 1.3.1.1安装更新的Gem,从here找到最新版本

或者 你可以这样做:

必须将文件jquery.cookie.js 放在文件夹vendor/assets/javascripts/ 中,然后在文件app/assets/javascripts/application.js 中调用它:

//= require jquery.cookie

之前

//= require_tree .

或任何其他需要jquery.cookie

你不需要脚本标签。

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多