My setup: Rails 3.0.9, Ruby 1.9.2
I want to check the gem version for my app through the Rails console. In my gemfile, I have
gem 'rack', '1.2.3'
Ran bundle install after.开发者_如何转开发 In the Rails console,
>> Rack.version
=> "1.1"
Any idea why?
UPDATE
Gemfile.lock
GEM
remote: http://rubygems.org/
specs:
actionpack (3.0.9)
...
rack (~> 1.2.1)
...
rack (1.2.3)
rack-mount (0.6.14)
rack (>= 1.0.0)
warden (1.0.4)
rack (>= 1.0)
DEPENDENCIES
...
rack (= 1.2.3)
...
There are several rack versions listed in gemfile.lock
.
Rack.version
will return the protocol version,
Rack.release
is probably what you are you looking for.
https://github.com/rack/rack/blob/master/lib/rack.rb#L14
Otherwise:
Gem.loaded_specs["rack"]
Example:
Gem.loaded_specs["rack"]
# => #<Gem::Specification name=rack version=1.3.2>
Gem.loaded_specs["rack"].version
# => #<Gem::Version "1.3.2">
Gem.loaded_specs["rack"].version.to_s
# => "1.3.2"
Every gem has ::VERSION constant.. so just use Rack::VERSION or OpenSSL::VERSION in console which should give you the version of gem loaded in that console.
we can use bundle list
or bundle show
to list all Gems included by the bundle.
Maybe you have multiple version of rack installed, try running gem uninstall rack
and see if it offers you two options to choose from, Rack 1.1 and Rack 1.2.3. If so, choose to uninstall Rack 1.1.
If this still does not work, just uninstall Rack and try running bundle update.
I had this problem when I was using multiple rake versions 0.8.7 and 0.9.2, this helped me.
精彩评论