如何请求ActiveResource

发布于 2024-11-09 08:39:50 字数 631 浏览 0 评论 0原文

我想在 Rails 中测试我的 RESTful 资源:

require 'rubygems'
require 'activeresource'

class Event < ActiveResource::Base
  self.site = "http://localhost:3000"
end

events = Event.find(:all)
puts events.map(&:name)

我已经安装了 gem:

gem安装activeresource

但是当我启动代码时,我收到错误消息:

<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- activeresource (LoadError)
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from service.rb:2:in `<main>'

我如何需要 ActiveResource?

I want to test my RESTful resource in Rails:

require 'rubygems'
require 'activeresource'

class Event < ActiveResource::Base
  self.site = "http://localhost:3000"
end

events = Event.find(:all)
puts events.map(&:name)

I have installed gem:

gem install activeresource

But when I launch my code I get the error message:

<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- activeresource (LoadError)
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from service.rb:2:in `<main>'

How can I require ActiveResource?

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

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

发布评论

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

评论(3

霊感 2024-11-16 08:39:50

您的需求中有一个拼写错误,以下是正确的:

require 'active_resource'

There is a typo in your require, the following is the correct one:

require 'active_resource'
秋日私语 2024-11-16 08:39:50

有了bunder,你就可以做到这一点,

gem "activeresource", require: "active_resource"

通常gems需要名称等于gem名称的文件,用gem“foo”:require =>; bar 语法您可以指定默认包含的不同文件。

With bunder you can do this just with

gem "activeresource", require: "active_resource"

Normally gems requires file with name equal to gem’s name, with gem "foo" :require => bar syntax you can specify different file to be included by default.

兮子 2024-11-16 08:39:50

我认为你可以这样做:

require 'rubygems'
gem 'activeresource'
require 'active_resource'

你还可以指定你想要的 activeresource 版本

gem 'activeresource', '=3.0.7'

例如, 。或者您可以完全省略这一行,但这样它会更干净......并且可以确保您获得正确的版本。

希望这有帮助,NoICE

i think you can do it this way:

require 'rubygems'
gem 'activeresource'
require 'active_resource'

You can also specify which version of activeresource you want by

gem 'activeresource', '=3.0.7'

for example. Or you can omit this line completely, but this way it's cleaner... and it makes sure that you get the right version.

Hope this helps, NoICE

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