Ruby on rails 注释命令无效,已将其添加到我的文件中

Ruby on rails 注释命令无效,已将其添加到我的文件中,ruby-on-rails,ruby,ruby-on-rails-3,rubygems,gem,Ruby On Rails,Ruby,Ruby On Rails 3,Rubygems,Gem,我的gem文件看起来像: group :development, :test do gem 'rspec-rails' gem 'annotate-models', '1.0.4' end 我运行了“bundle install”,它安装了annotate models bundle 如果我键入:annotate我会得到一个命令notfound错误 如果我键入:bundle show annotateI得到一个“在当前bundle中找不到gem annotate” 如果我键

我的gem文件看起来像:

 group :development, :test do
    gem 'rspec-rails'
    gem 'annotate-models', '1.0.4'
 end
我运行了“
bundle install
”,它安装了annotate models bundle

如果我键入:
annotate
我会得到一个命令notfound错误

如果我键入:
bundle show annotate
I得到一个“在当前bundle中找不到gem annotate”

如果我键入bundle show annotate models,它会说它安装在:

/Library/Ruby/Gems/1.8/gems/annotate-models-1.0.4
打字:

annotate-models
也不行


我在railstutorial.org中跟随,并在这一点上陷入困境。

我认为您的PATH env变量缺少指向gems bin目录的路径。
我想应该是:
/Library/Ruby/Gems/1.8/bin

我是新手,但是我在编写rails教程时遇到了这个问题,但是通过将Gems-bin路径添加到path-env变量中,我就能够解决这个问题。(正如格塔斯在上面的几篇帖子中所说)

首先在命令提示符中:

gem list -d annotate
你会得到这样的结果

:注释模型(1.0.4) 作者:戴夫·托马斯 鲁比福尔: 主页:h'ttp://annotate-models.rubyforge.org 安装于:C:/ruby192/lib/ruby/gems/1.9.1

关键是:

安装于:C:/ruby192/lib/ruby/gems/1.9.1

因此,在本例中,将/bin添加到该路径中,例如我使用的:C:\ruby192\lib\ruby\gems\1.9.1\bin是要添加到path环境变量中的内容

要更改Vista上的PATH环境变量,请执行以下操作:控制面板>>系统>>高级系统设置(左侧链接)。打开该框后,单击“高级”选项卡,然后单击“环境变量”按钮。然后在系统变量上找到路径变量并单击编辑按钮。由于路径由分号分隔,因此添加
;C:\ruby192\lib\ruby\gems\1.9.1\bin
在变量值字段的末尾

应该是这样的 `一些/路径;一些其他路径;C:\ruby192\lib\ruby\gems\1.9.1\bin` 当您完成时


保存它,然后关闭并重新打开命令提示符。从那以后,annotate和rspec开始为我工作。祝您好运。

您应该在捆绑环境中使用以下命令运行该命令:

$ bundle exec annotate
查看以了解更多详细信息。

编辑:更好的版本(使用Bundler仅为当前项目安装)

  • gem'注释'
    添加到gem文件
  • 运行
    $bundle安装
  • 运行
    $bundle exec annotate
  • Edit2:现在看来您必须明确指定注释版本,因此在Gemfile中put
    gem'annotate',2.4.1.beta1'
    (这是一个预发布的测试版gem,与最新版本的activerecord一起使用,而不是直接指定github repo)

    Edit3:2.5.0决赛现在已经出炉了,所以希望没有必要再强制推出测试版了,只需要获得最新版本就可以了

    旧版本(也在系统级安装gem):

    如果运行轨道3,则钻机为:

  • 运行
    $sudo gem安装注释
  • gem'注释'
    添加到gem文件
  • 运行
    $bundle安装
  • 运行
    $annotate
  • 开心点:)

  • 对我来说,答案是:

    投票最多的答案对我来说并不完全有效,因为我在遵循建议的解决方案时遇到了额外的错误:

    undefined method `namespace' for main:Object (NoMethodError)
    
    我在下面列出了对我有用的东西(我在Ubuntu11.10下使用Ruby 1.9.2和Rails 3.1.3):

  • 安装注释

    $ gem install annotate
    
  • 添加以下行来修改Gemfile

    gem 'annotate', 
        :git => 'git://github.com/jeremyolliver/annotate_models.git', 
        :branch => 'rake_compatibility'
    
  • 安装捆绑包

    $ bundle install    
    
  • 现在,您可以使用注释,如下所示:

    $ bundle exec annotate
    
  • 使用

    而不是

    gem 'annotate-models', '1.0.4'
    

    看起来gem名称在RubyGems.org上更改了。

    您可以将其用于Rails 4,在gem文件gem“annotate”、“~>2.5.0”中添加gem,然后运行以下命令

    rails g annotate_models:install
    
    而不是

    rails g annotate:install
    
    然后运行以下命令在模型类之后添加模式信息

    bundle exec annotate -p after
    
    或者之前可以使用下面的方法

     bundle exec annotate -p before
    

    Bundler也可以在Rails2.x中使用,但我猜也是Rails3。致OP:想与大家分享吗?是的,我正在使用Rails 3.0,它在3.0中不起作用?我也在学习教程。根据此处接受的答案成功安装后,我在bundle安装时出现以下错误:“在gem文件中列出的任何gem源中找不到gem‘annotate models(>=0)”-我的gem文件中有一行关于gem‘注释模型’-有人知道问题出在哪里吗?+1这对我来说在Mac OS X 10.6、ruby 1.8.7和Rails 3.0.3上很有效。我认为‘sudo’是让它在Mac OS上运行的关键。我必须做“rvm gem install annotate”好的,但是你能解释一下为什么吗?这是否意味着rails 3版本的annotate models gem不在rubygems.org源代码中,因此我们需要通过gem工具安装它?只是好奇。。。(编辑:没关系,gem现在显然被命名为annotate,而不是annotate models!)我仍然收到这个错误。Mac上的rails 3.1.3。它显示我已经安装了annotate 2.4(在执行gem list-d annotate时)。
     bundle exec annotate -p before