NoMethodError: undefined method `configure' for main:Object on sinatra project

NoMethodError: undefined method `configure' for main:Object on sinatra project

所以我一直在关注这个关于使用 Sinatra 设置 postgres 数据库的相当古老的教程:http://mherman.org/blog/2013/06/08/designing-with-class-sinatra-plus-postgresql-plus-heroku/

我已经按照建议设置了 environments.rb 和 rake 文件,如下所示:

configure :development do
  set :database, "sqlite:///dev.db"
  set :show_exceptions, true
end

configure :production do
  db = URI.parse(ENV["DATABASE_URL"] || 'postgres:///localhost/mydb')

  ActiveRecord::Base.establish_connection(
    :adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
    :host => db.host,
    :username => db.user,
    :password => db.password,
    :database => db.path[1..-1],
    :encoding => 'utf8'
  )

end

和:

require './app_name'
require 'sinatra/activerecord/rake'

当我尝试使用以下方法创建迁移时:

rake db:create_migration NAME=create_applicants

它的错误是:

NoMethodError: undefined method `configure' for main:Object
/Users/harxy/Projects/bridgey/environments.rb:1:in `<top (required)>'

想知道这里可能出了什么问题吗?

谢谢。

根据 Jack Bracken 的上述评论,您的 environments.rb 文件中需要 require 'sinatra' 才能正常工作。