rails 3: gems installed successfully, but cannot u

2019-09-05 05:47发布

I did a clean install of rails 3.0.6. My app is running fine, except that I cannot use all the gems that didn't come with rails 3. All of them are in gem list. I also have them in Gemfile and have ran bundle install and bundle update.

For example, with matthuhiggins-foreigner:

upon rake db:migrate, it complains that add_foreign_key is not defined.

I have the same problem with less:

no .css generated from .less)

geokit-rails3:

Unknown key(s): origin, within

gem which geokit-rails3 returns:

/Library/Ruby/Gems/1.8/gems/geokit-rails3-0.1.3/lib/geokit-rails3.rb

gem environment returns:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.5.0
  - RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-10
  - GEM PATHS:
     - /Library/Ruby/Gems/1.8
     - /Users/administrator/.gem/ruby/1.8
     - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

I have looked into this problem for a long time. Please help! Thanks!

3条回答
相关推荐>>
2楼-- · 2019-09-05 06:09

Rails 3 does not load any gems that are not listed in your Gemfile, even if they are installed on your system. You need to explicitly list them there first.

The typical workflow in R3 is not to install your gems and then use them, but to write entries in the Gemfile and then install them by installing bundler with "gem install bundle" and getting all the remaining gems with "bundle install". Bundle install will install any required gems you do not already have, but will use the ones you do have.

(Bundle update, suggested by another user, will bump all your gems to the most recent available version that matches your requirements as laid out in the Gemfile, even if the ones already installed satisfy the requirements). i.e. if you need foo_gem >= 1.0 and you have foo_gem 1.0.1 installed, "bundle install" won't change it but "bundle update" will install foo_gem 1.0.3 if it's available.

If you are working on multiple applications that have conflicting (or potentially conflicting) gems, then I recommend learning about RVM and creating a gemset for each project. This is especially valuable if you are still working on any Rails 2.x projects alongside your R3 projects.

查看更多
狗以群分
3楼-- · 2019-09-05 06:28

I came back to this problem after a few days and I fixed all the issues!

matthuggins-foreigner gem is called foreigner, so I added this to Gemfile: gem 'foreigner'

With geokit, I simply followed the instructions here: https://github.com/jlecour/geokit-rails3

With less, I installed the less gem and the more plugin, then restarted the server: https://github.com/cloudhead/more

查看更多
闹够了就滚
4楼-- · 2019-09-05 06:33

Try this:

  1. Update gem by running gem update --system
  2. Make sure your gemfile lists the gems
  3. Run bundle update to update all your gems in the gemfile

Hopefully that should do the trick.

查看更多
登录 后发表回答