过去10天我和mongodb一起学习ROR。我无法在安装过程中获得mongoid_slug工作。请查看我在http://pastebin.com/Gtjzx3Xp
获得的内容我有gem mongoid(3.0.4,3.0.1)。我的Gemfile看起来像:
source 'https://rubygems.org'
gem 'rails', '3.2.6'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem "mongoid", "~> 3.0.0"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'mongoid_slug'
gem 'stringex'
然后,
$> bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Bundler could not find compatible versions for gem "mongoid":
In Gemfile:
mongoid_slug (>= 0) ruby depends on
mongoid (~> 2.0.0.beta7) ruby
mongoid (3.0.1)
我的控制器是:
class Post
include Mongoid::Document
include Mongoid::Slug
field :name, type: String
field :title, type: String
field :content, type: String
validates :title, :presence => true, :length => { :minimum => 10 }
has_many :comments
slug :name
end
在网页上,当我跑步时,我得到:
Routing Error
uninitialized constant Mongoid::Slug
Try running rake routes for more information on available routes.
mongoid_slug不适用于当前版本的mongoid吗?我怎样才能让它发挥作用?
答案 0 :(得分:2)
RubyGems version of mongoid_slug似乎已过时;那个人想要Mongoid 2.0(mongoid ~> 2.0
),那就是你的bundle install
错误来自哪里。 GitHub version似乎是for Mongoid 3.0:
s.add_dependency 'mongoid', '~> 3.0'
所以你可以尝试在你的Gemfile中使用它:
gem 'mongoid_slug', :git => 'git://github.com/hakanensari/mongoid-slug.git'
使用GitHub版本。
答案 1 :(得分:0)
这里最可能的答案是你的mongoid_slug版本太低了。尝试在Gemfile中指定最新版本:
gem 'mongoid_slug', '0.10.0'
然后bundle update mongoid_slug
,看看是否能解决问题。