Ruby on rails RubyonRails类被误认为是常量

Ruby on rails RubyonRails类被误认为是常量,ruby-on-rails,ruby,Ruby On Rails,Ruby,首先,我第一次尝试RubyonRails。 我正在做一个简单的练习,设计一个表单来接收事件信息并将这些事件保存在谷歌日历中。 要在Google日历上保存事件,我将使用以下gem: 我有以下视图代码 <h1>Welcome to Ruby On Rails Calendar</h1> <h3>Add Event</h3> <form action="/google_calendar/create" method="post"> &l

首先,我第一次尝试RubyonRails。 我正在做一个简单的练习,设计一个表单来接收事件信息并将这些事件保存在谷歌日历中。 要在Google日历上保存事件,我将使用以下gem:

我有以下视图代码

<h1>Welcome to Ruby On Rails Calendar</h1>

<h3>Add Event</h3>
<form action="/google_calendar/create" method="post">
  <table>
    <tr>
      <td>Title</td><td><input type="text" /></td>
    </tr>
    <tr>
      <td>Begin Date</td><td><input type="date" name="begindate" id="bagindate" /><input type="time" name="beginhour"  id="beginhour" /></td>
    </tr>
    <tr>
      <td>End Date</td><td><input type="date" name="enddate" id="enddate" /><input type="time" name="endhour" id="endhour" /></td>
    </tr>
    <tr>
      <td>Local</td><td><input type="text" name="local" id="local" /></td>
    </tr>
    <tr>
      <td>Description</td><td><input type="textarea" rows="10" name="description" id="description" /></td>
    </tr>
    <tr>
     <td><input type="Submit" value="Save" /></td>
    </tr>
  </table>
</form>

<%= @result_message %>
据推测,GData是谷歌日历gem中定义的一个类,但似乎没有被认可

我的gem文件中有
gem'googlecalendar'
,是否安装了
bundle
,当我执行
bundle show googlecalendar
时,它就会出现


有人知道这是什么原因吗?

文档有点错误

试试这个

require 'googlecalendar'
google_calendar_service = Googlecalendar::GData.new
因为您没有指定名称空间,所以Ruby首先在
全局名称空间中搜索了它,但没有找到,所以希望它是
GoogleCalendarController::GData


工具书类 代码来自gem的lib/googlecalendar.rb,您可以看到名称空间是googlecalendar

$:.unshift(File.dirname(__FILE__)) unless
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

module Googlecalendar
  # List of lib files to include
  FILES = %w{calendar.rb dsl.rb event.rb gcalendar.rb gdata.rb ical.rb net.rb version.rb}
end

# Add all FILES as require
Googlecalendar::FILES.each { |f| require "googlecalendar/#{f}"}

也许您需要在控制器类的顶部设置“googlecalendar”?请尝试
::GData.new
,如果它是在根名称空间中定义的,请尝试将
require'googlecalendar'
放在类定义的正下方的顶部实际上我已经尝试了require'googlecalendar'放在控制器的顶部和类定义的正后方,但它不起作用。With::GData.new它也不起作用,有没有办法检查类名称空间?@Andre:没有“类名称空间”这样的东西。类是与任何其他对象一样的对象。它们可以从方法返回。它们可以作为参数传递给方法。它们可以分配给变量。通常,它们被分配给常量。谢谢,就是这样。以前我实际上试过GoogleCalendar::GData.new(大写字母为“C”),但没有成功。现在我得到了一个与SSL相关的错误,但至少这个问题已经解决了。这是新的错误。SSL_connect返回=1 errno=0 state=SSLv3读取服务器证书B:证书验证失败我正在考虑放弃此gem并尝试更好的选择。是的,我支持你;试着找到更简单的解决方案,比如谢谢,我还没有找到。
require 'googlecalendar'
google_calendar_service = Googlecalendar::GData.new
$:.unshift(File.dirname(__FILE__)) unless
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

module Googlecalendar
  # List of lib files to include
  FILES = %w{calendar.rb dsl.rb event.rb gcalendar.rb gdata.rb ical.rb net.rb version.rb}
end

# Add all FILES as require
Googlecalendar::FILES.each { |f| require "googlecalendar/#{f}"}