I need to have different versions of a gem for development and production, so I put the following in my 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
but if i try to do bundle install
or even just rails console
I get the above error
I have tried
bundle install --without production
but I still get the error message. FYI: I need to do this because I am going thru the rails tutorial and there is a conflict that arises between windows, ruby 2.0.0 and bcrypt and Heroku so I am using bcrypt 3.1.2 on windows (with a modification to the active record gemfile) and bcrypt 3.0.1 on Heroku.
See this for more details: Issues using bcrypt 3.0.1 with ruby2.0 on Windows
I basically did what is mentioned in the first answer
EDIT
###################################################################
As the answer below points out, I really should be using the same version in both production and development (even tho I am just working thur a tutorial). What I ended up doing is monkey patching ActiveModel to use
gem 'bcrypt-ruby', '3.1.2'
rather than
gem 'bcrypt-ruby', '~> 3.0.0'
in secure_password.
I accomplished this by placing the following in 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
and then adding the following to config/environment.rb
require File.expand_path('../../lib/secure_password_using_3_1_2.rb', __FILE__)
There are several ways to specify gem versions: Use a specific version: gem "name-of-gem", "1.0" . You can find specific versions on Rubygems.org (provided that's the source you”re using) by searching for your gem and looking at the “Versions” listed. Use a version operator: gem "name-of-gem", ">1.0" .
Install BundlerSelect Tools | Bundler | Install Bundler from the main menu. Press Ctrl twice and execute the gem install bundler command in the invoked popup. Open the RubyMine terminal emulator and execute the gem install bundler command.
The Gemfile. lock allows you to specify the versions of the dependencies that your application needs in the Gemfile , while remembering all of the exact versions of third-party code that your application used when it last worked correctly. By specifying looser dependencies in your Gemfile (such as nokogiri ~> 1.4.
Gemfile. lock is automatically generated when you run bundle install or bundle update . It should never be edited manually.
How about this?
gem "my_gem", ENV["RAILS_ENV"] == "production" ? "2.0" : "1.0"
RAILS_ENV=production bundle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With