我从命令行安装了一个gem:
sudo gem install jalalidate
宝石说它安装了:
$ gem list jalalidate
*** LOCAL GEMS ***
jalalidate (0.3.2)
可以加载:
ruby -rubygems -e 'require "jalalidate"' # output is empty, (success?)
虽然当我尝试在Rakefile中包含这个gem时,rake失败了:
# Rakefile:
require "rubygems"
require "bundler/setup"
require "stringex"
require "jalalidate"
# Terminal:
$ rake new_post["title"]
rake aborted!
cannot load such file -- jalalidate
(See full trace by running task with --trace)
注意:
Time.now.strftime('%Y-%m-%d %H:%M')
生成的日期转换为Jalali日历系统,(JalaliDate.new(Date.today).strftime('%Y-%m-%d')
)。更新
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.11
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /var/lib/gems/1.9.1
- /home/soroush/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
答案 0 :(得分:1)
在您尝试要求Rakefile
之前,require "bundler/setup"
已jalalidate
,这意味着您正在使用Bundler,因此您拥有Gemfile
,这限制了宝石(和版本)可用。
要在项目中使用gem,请添加行
gem "jalalidate"
到Gemfile
。
答案 1 :(得分:0)
请参阅this question,了解为什么在gem命令中使用sudo主要是一个坏主意。
我建议您尝试在没有sudo的情况下安装gem:gem install jalalidate