Rake gems:遵循声明性授权 Railscast 时安装会产生错误

发布于 2024-12-29 10:37:11 字数 2257 浏览 0 评论 0原文

我正在关注 Railstcast #188 以获取在我的 Rails 3 应用程序(使用 Ruby 1.9.2)上运行的声明性授权,并且在安装 gem 时遇到了问题。

Ryan 建议将其添加到 config/environment.rb 中,内容如下:

config.gem "declarative_authorization", :source => "http://gemcutter.org"

然后使用 sudo rake gems:install 安装它。

但是,当我尝试这样做时,出现错误:

/Users/Travis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems.rb:314:in `bin_path': can't find gem rake ([">= 0"]) with executable rake (Gem::GemNotFoundException)

我尝试了 rake gems:install,但收到了此错误:

Don't know how to build task 'gems:install'

安装 declarative_authorization 的说明位于 GitHub 推荐了一个不同的流程,我也遵循了该流程,但仍然无法通过 rake:gems install

有谁知道可能会发生什么,以便我可以解决这个问题?

更新: 这是我的 config/environment.rb 的样子:

RVM -v: rvm 1.10.0-pre 宝石清单:

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.9, 3.0.5)
actionpack (3.0.9, 3.0.5)
activemodel (3.0.9, 3.0.5)
activerecord (3.0.9, 3.0.5)
activeresource (3.0.9, 3.0.5)
activesupport (3.0.9, 3.0.5)
addressable (2.2.6)
arel (2.0.10)
aws-s3 (0.6.2)
aws-sdk (1.3.2)
builder (2.1.2)
bundler (1.0.21 ruby)
cocaine (0.2.1, 0.2.0)
erubis (2.6.6)
faraday (0.7.6, 0.7.5)
fastercsv (1.5.4)
gemcutter (0.7.1)
heroku (2.14.0)
httparty (0.8.1)
i18n (0.6.0, 0.5.0)
jquery-rails (1.0.19, 1.0.16)
json (1.6.5)
launchy (2.0.5)
mail (2.2.19)
metaclass (0.0.1)
mime-types (1.17.2)
mocha (0.10.3, 0.10.2, 0.10.0)
multi_json (1.0.4)
multi_xml (0.4.1)
multipart-post (1.1.4)
nifty-generators (0.4.6)
nokogiri (1.5.0)
paperclip (2.5.2, 2.5.0, 2.4.5)
pg (0.12.2, 0.12.0, 0.11.0)
polyamorous (0.5.0)
polyglot (0.3.3)
rack (1.2.5, 1.2.4)
rack-mount (0.6.14)
rack-test (0.5.7)
rails (3.0.9, 3.0.5)
railties (3.0.9, 3.0.5)
rake (0.9.2.2, 0.9.2, 0.8.7)
rake-compiler (0.7.9)
ransack (0.6.0, 0.5.8)
rdoc (3.8)
rest-client (1.6.7)
rubyzip (0.9.5)
simple_oauth (0.1.5)
sqlite3 (1.3.5, 1.3.4)
sqlite3-ruby (1.3.3)
term-ansicolor (1.0.7)
thor (0.14.6)
treetop (1.4.10)
twitter (2.1.0, 2.0.2)
tzinfo (0.3.31, 0.3.30)
uuidtools (2.1.2)
xml-simple (1.1.1)

I'm following Railstcast #188 to get declarative authorization running on my Rails 3 app (using Ruby 1.9.2) and am running into an issue getting the gem to install.

Ryan suggests adding it in config/environment.rb with the following:

config.gem "declarative_authorization", :source => "http://gemcutter.org"

Then install it with sudo rake gems:install.

However when I try that I get an error:

/Users/Travis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems.rb:314:in `bin_path': can't find gem rake ([">= 0"]) with executable rake (Gem::GemNotFoundException)

I tried rake gems:install, but got this error:

Don't know how to build task 'gems:install'

The instructions to install declarative_authorization at GitHub recommend a different process, which I also followed but still couldn't get past rake:gems install.

Does anyone know what may be happening so I can get around this?

UPDATE: Here's what my config/environment.rb looks like:

RVM -v: rvm 1.10.0-pre
Gem list:

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.9, 3.0.5)
actionpack (3.0.9, 3.0.5)
activemodel (3.0.9, 3.0.5)
activerecord (3.0.9, 3.0.5)
activeresource (3.0.9, 3.0.5)
activesupport (3.0.9, 3.0.5)
addressable (2.2.6)
arel (2.0.10)
aws-s3 (0.6.2)
aws-sdk (1.3.2)
builder (2.1.2)
bundler (1.0.21 ruby)
cocaine (0.2.1, 0.2.0)
erubis (2.6.6)
faraday (0.7.6, 0.7.5)
fastercsv (1.5.4)
gemcutter (0.7.1)
heroku (2.14.0)
httparty (0.8.1)
i18n (0.6.0, 0.5.0)
jquery-rails (1.0.19, 1.0.16)
json (1.6.5)
launchy (2.0.5)
mail (2.2.19)
metaclass (0.0.1)
mime-types (1.17.2)
mocha (0.10.3, 0.10.2, 0.10.0)
multi_json (1.0.4)
multi_xml (0.4.1)
multipart-post (1.1.4)
nifty-generators (0.4.6)
nokogiri (1.5.0)
paperclip (2.5.2, 2.5.0, 2.4.5)
pg (0.12.2, 0.12.0, 0.11.0)
polyamorous (0.5.0)
polyglot (0.3.3)
rack (1.2.5, 1.2.4)
rack-mount (0.6.14)
rack-test (0.5.7)
rails (3.0.9, 3.0.5)
railties (3.0.9, 3.0.5)
rake (0.9.2.2, 0.9.2, 0.8.7)
rake-compiler (0.7.9)
ransack (0.6.0, 0.5.8)
rdoc (3.8)
rest-client (1.6.7)
rubyzip (0.9.5)
simple_oauth (0.1.5)
sqlite3 (1.3.5, 1.3.4)
sqlite3-ruby (1.3.3)
term-ansicolor (1.0.7)
thor (0.14.6)
treetop (1.4.10)
twitter (2.1.0, 2.0.2)
tzinfo (0.3.31, 0.3.30)
uuidtools (2.1.2)
xml-simple (1.1.1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千寻… 2025-01-05 10:37:11

不确定您的环境是如何设置的,但只需安装 rake 就可以了。如果您提供更多详细信息(rvm、bundler 等),可能会有所帮助。

gem install rake

进一步检查您的路径后,我发现您正在使用 RVM。如果您的路径安装正确,您可以使用 RVM Global gemset,执行上面的行。

我的另一个建议是查看 CanCan Railscast,因为这是当今授权的更大规范,也有更多的支持者。

http://railscasts.com/episodes/192-authorization-with-cancan

“几集前我们介绍了声明式授权。虽然它是 Rails 的一个出色的授权插件,但对于更简单的站点来说可能有点繁重。在编写关于声明式授权的 Railscast 后,Ryan Bates 寻找替代方案解决方案,但未能找到适合他需求的解决方案,因此决定编写自己的 CanCan。” - RBates

了解您的环境后,让我们尝试将环境稍微分开。这样做。

rvm gemset create some_other_name
rvm gemset use some_other_name
bundle install

看看这是否足以隔离您的环境。

编辑:我不再使用 rake gems:install 。您已经安装了捆绑程序,我假设您想使用它。当存在此类文档时,我确实使用rails g gemname:install,我将再次查看railscasts,看看rbates告诉你什么。

在 CANCAN github 页面上,它说:在 Rails 3 中,将其添加到您的 Gemfile 中并运行捆绑命令。
宝石“康康”。

Not sure how your environment is set up, but simply installing rake should do it. If you provide more detail (rvm, bundler, etc.) it may be of help.

gem install rake

Upon further inspection of your path, I see you're using RVM. If your paths are installed properly, you can either use the RVM Global gemset, execute the line above.

Another suggestion I have is checking out the CanCan railscast as that is the bigger norm for authorization these days, more supporters as well.

http://railscasts.com/episodes/192-authorization-with-cancan

"A few episodes ago we covered Declarative Authorization. While it is an excellent authorization plugin for Rails it can be a little heavy for simpler sites. After writing the Railscast on Declarative Authorization Ryan Bates looked for an alternative solution and, failing to find one that suited his needs, decided to write his own, CanCan." - RBates

After seeing your environment, let's try to separate the environments a little. Do this.

rvm gemset create some_other_name
rvm gemset use some_other_name
bundle install

See if this isolates your environment enough.

EDIT: I don't use rake gems:install anymore. You have bundler installed, and I'm assuming you want to use it. I do use rails g gemname:install when the documentation for such exists, I'm going to look at the railscasts again and see what rbates is telling you.

On the CANCAN github page, it says: In Rails 3, add this to your Gemfile and run the bundle command.
gem "cancan".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文