名称错误在/ contacts uninitialized constant Contact :: GoogleDrive

时间:2014-06-28 07:11:15

标签: 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 :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

1 个答案:

答案 0 :(得分:0)

发现问题:

  1. 意外安装了&#39; google-drive&#39;宝石而不是“google_drive”&#39;宝石
  2. 在secrets.yml文件中,我有实际的用户名,密码等,而不是&#39; GMAIL_USERNAME&#39;然后会查看我的bashrc文件。