Sinatra数据库错误 - rake中止了未初始化的常量EN

时间:2014-08-13 03:34:43

标签: activerecord sinatra

Ruby / Sinatra / Rails的全新内容,并根据this post设置一个小应用

所有内容都顺利运行,直到我尝试通过命令行创建数据库,其中包含以下内容:rake db:create_migration NAME=create_model

我得到的错误如下:

rake aborted!
uninitialized constant EN
(erb):4:in `<main>'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/erb.rb:849:in `eval'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/erb.rb:849:in `result'
/Library/Ruby/Gems/2.0.0/gems/sinatra-activerecord-2.0.2/lib/sinatra/activerecord.rb:32:in `database_file='
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1208:in `set'
/Library/Ruby/Gems/2.0.0/gems/sinatra-activerecord-2.0.2/lib/sinatra/activerecord.rb:20:in `registered'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1391:in `block in register'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1389:in `each'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1389:in `register'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1970:in `register'
/Library/Ruby/Gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:2032:in `register'
/Library/Ruby/Gems/2.0.0/gems/sinatra-activerecord-2.0.2/lib/sinatra/activerecord.rb:53:in `<module:Sinatra>'
/Library/Ruby/Gems/2.0.0/gems/sinatra-activerecord-2.0.2/lib/sinatra/activerecord.rb:10:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
/Users/pbj/Desktop/code/rbapp/app.rb:3:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/Users/pbj/Desktop/code/rbapp/Rakefile:1:in `<top (required)>'
/Library/Ruby/Gems/2.0.0/gems/rake-10.1.1/lib/rake/rake_module.rb:25:in `load'
/Library/Ruby/Gems/2.0.0/gems/rake-10.1.1/lib/rake/rake_module.rb:25:in `load_rakefile'
/Library/Ruby/Gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:637:in `raw_load_rakefile'
/Library/Ruby/Gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:94:in `block in load_rakefile'
/Library/Ruby/Gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling'
/Library/Ruby/Gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:93:in `load_rakefile'
/Library/Ruby/Gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:77:in `block in run'
/Library/Ruby/Gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling'
/Library/Ruby/Gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:75:in `run'
/usr/bin/rake:37:in `<main>'

Rake文件:

require 'sinatra/activerecord/rake'
require './app'

app.rb文件

# require 'rubygems'
require 'sinatra'
require 'sinatra/activerecord'
require './config/environments' #database configuration
require './models/model'


get '/' do 
    "Hello, bitch"
end

config.ru

require './app'
run Sinatra::Application

的Gemfile

source "https://rubygems.org"

gem "sinatra"
gem 'activerecord'
gem 'sinatra-activerecord'
gem 'pg'

config文件夹中的database.yml

development: 
    adapter: postgresql
    database: development
    username: <%= EN['PG_USER'] %>
    password: <%= EN['PG_PASS'] %>
    host: localhost
配置文件夹中的

environments.rb
configure :production, :development 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

0 个答案:

没有答案