Ruby on rails 4 /contacts未初始化常量Contact::GoogleDrive处的名称错误
我现在正在学习“RailsApps项目”Rails 4.1教程,并且一直停留在电子表格连接部分。在测试应用程序时,我遇到以下错误:Ruby on rails 4 /contacts未初始化常量Contact::GoogleDrive处的名称错误,ruby-on-rails-4,Ruby On Rails 4,我现在正在学习“RailsApps项目”Rails 4.1教程,并且一直停留在电子表格连接部分。在测试应用程序时,我遇到以下错误: NameError at /contacts uninitialized constant Contact::GoogleDrive update_spreadsheet () Users/sikendersingh/sideshow/learn-rails/app/models/contact.rb validates_presence_of :conte
NameError at /contacts
uninitialized constant Contact::GoogleDrive
update_spreadsheet () Users/sikendersingh/sideshow/learn-rails/app/models/contact.rb
validates_presence_of :content
validates_format_of :email, :with => /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}\z/i
validates_length_of :content, :maximum => 500
def update_spreadsheet
connection = GoogleDrive.login(Rails.application.secrets.email_provider_username, Rails.application.secrets.email_provider_password
)
ss = connection.spreadsheet_by_title('Learn-Rails-Example')
if ss.nil?
ss = connection.create_spreadsheet('Learn-Rails-Example')
end
以下是整个文件:
class Contact < ActiveRecord::Base
has_no_table
column :name, :string
column :email, :string
column :content, :string
validates_presence_of :name
validates_presence_of :email
validates_presence_of :content
validates_format_of :email, :with => /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}\z/i
validates_length_of :content, :maximum => 500
def update_spreadsheet
connection = GoogleDrive.login(Rails.application.secrets.email_provider_username, Rails.application.secrets.email_provider_password
)
ss = connection.spreadsheet_by_title('Learn-Rails-Example')
if ss.nil?
ss = connection.create_spreadsheet('Learn-Rails-Example')
end
ws = ss.worksheets[0]
last_row = 1 + ws.num_rows
ws[last_row, 1] = Time.new
ws[last_row, 2] = self.name
ws[last_row, 3] = self.email
ws[last_row, 4] = self.content
ws.save
end
end
class联系人/\A[-A-z0-9\+\.]+\@([-A-z0-9]+\.)+[A-z0-9]{2,4}\z/i
验证的长度为:content,:max=>500
def更新电子表格
connection=GoogleDrive.login(Rails.application.secrets.email\u provider\u用户名,Rails.application.secrets.email\u provider\u密码
)
ss=连接。电子表格按标题(“Learn-Rails-Example”)
如果ss.nil?
ss=连接。创建_电子表格('Learn-Rails-Example')
终止
ws=ss.工作表[0]
最后一行=1+ws.num行
ws[最后一行,1]=Time.new
ws[last_row,2]=self.name
ws[最后一行,3]=self.email
ws[最后一行,4]=self.content
ws.save
终止
终止
发现问题:
你安装了gem'google_drive'吗?是的,全部安装了,这是我的gem文件:ource'ruby'2.1.1'gem'rails',4.1.1'#rails defaults gem'sqlite3'gem'sass rails','~>4.0.3'gem'uglifier','>=1.3.0'gem'coffee rails','~>4.0.0'gem'jquery rails'gem'turbolinks'gem'jbuilder,'>2.0'gem'spring',小组::开发#学习rails gem'activerecord无表'gem'基础rails'gem'长臂猿'gem'谷歌硬盘'gem'高压'gem'简单形式'gem'小组:开发做gem'更好的错误'gem'安静的资产'gem'rails\u布局'end