【发布时间】:2014-01-03 23:52:28
【问题描述】:
我需要有不同版本的 gem 用于开发和生产,所以我将以下内容放在我的 gemfile 中。
group :development, :test do
gem 'rspec-rails', '2.11.0'
gem 'bcrypt-ruby', '3.1.2'
end
group :production do
gem 'rails_12factor'
gem 'bcrypt-ruby', '3.0.1'
end
但如果我尝试做bundle install 甚至只是rails console 我会收到上述错误
我试过了
bundle install --without production
但我仍然收到错误消息。 供参考: 我需要这样做,因为我正在阅读 rails 教程,并且在 windows、ruby 2.0.0 和 bcrypt 和 Heroku 之间出现了冲突 所以我在 Windows 上使用 bcrypt 3.1.2(修改了活动记录 gemfile) 和 Heroku 上的 bcrypt 3.0.1。
更多详情请看这里: Issues using bcrypt 3.0.1 with ruby2.0 on Windows
我基本上做了第一个答案中提到的事情
编辑
###################################################################
正如下面的答案所指出的,我真的应该在生产和开发中使用相同的版本(即使我只是在学习教程)。 我最终做的是猴子修补 ActiveModel 以使用
gem 'bcrypt-ruby', '3.1.2'
而不是
gem 'bcrypt-ruby', '~> 3.0.0'
在安全密码中。
我通过将以下内容放入 lib/secure_password_using_3_1_2.rb 来完成此操作
module ActiveModel
module SecurePassword
extend ActiveSupport::Concern
module ClassMethods
def has_secure_password
# Load bcrypt-ruby only when has_secure_password is used.
# This is to avoid ActiveModel (and by extension the entire framework) being dependent on a binary library.
#gem 'bcrypt-ruby', '~> 3.0.0'
gem 'bcrypt-ruby', '3.1.2'
require 'bcrypt'
attr_reader :password
validates_confirmation_of :password
validates_presence_of :password_digest
include InstanceMethodsOnActivation
if respond_to?(:attributes_protected_by_default)
def self.attributes_protected_by_default
super + ['password_digest']
end
end
end
end
end
end
然后将以下内容添加到 config/environment.rb
require File.expand_path('../../lib/secure_password_using_3_1_2.rb', __FILE__)
【问题讨论】:
-
你说你得到“上述错误”,但你没有提供错误。
-
对不起...它在我的标题中,但它太长了。基本上它抱怨我在 gem 文件中有两个版本。我现在不在电脑前,所以我现在不能给出确切的信息
标签: ruby-on-rails ruby ruby-on-rails-3 heroku