我试图运行一个基本的Sinatra应用程序。当我到达' rackup'我得到一个错误:
/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:3:in `<top (required)>': undefined method `namespace' for main:Object (NoMethodError)
这似乎是Rake gem中的范围问题。我没有找到答案的运气,我不太确定需要修复什么。我确实更新了我所有的宝石,希望无济于事。这是我的代码,可能有助于....
rakefile.rb
require "./frank"
require "sinatra/activerecord/rake"
config.ru
require_relative 'frank'
map('/welcomes') { run WelcomesController }
frank.rb
require 'sinatra/base'
require 'active_record'
require 'bcrypt'
Dir.glob('./{controllers,models}/*rb').each { |file| require file }
ENV['SINATRA_ENV'] ||= 'development'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => "db/#{ENV['SINATRA_ENV']}.sqlite"
)
spec_helper.rb
ENV['SINATRA_ENV'] = 'test'
require_relative '../frank'
require 'capybara'
require 'database_cleaner'
Capybara.app = Rack::Builder.parse_file(File.expand_path('../../config.ru',__FILE__)).first
RSpec.configure do |config|
config.include Capybara::DSL
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
非常感谢:)
这低于主要错误:
from /Users/stephaniedean/.rvm/gems/ruby-2.2.1/gems/sinatra-activerecord-2.0.6/lib/sinatra/activerecord/rake.rb:1:in `load'
from /Users/stephaniedean/.rvm/gems/ruby-2.2.1/gems/sinatra-activerecord-2.0.6/lib/sinatra/activerecord/rake.rb:1:in `<top (required)>'
所以,它看起来像sinatra-activerecord而不仅仅是activerecord。我确实尝试过activerecord 3.2.17,但是没有用。感谢您的建议。
答案 0 :(得分:0)
在我找到解决方案之前,这占用了我数小时的时间:
http://aaronlerch.github.io/blog/sinatra-bundler-and-the-global-namespace/ https://github.com/sinatra/sinatra-contrib/issues/111
gem "sinatra", require: 'sinatra/base'
gem 'sinatra-activerecord', require: false
gem 'sinatra-contrib', require: false
require 'bundler/setup'
require 'rake'
require 'sinatra'
require 'sinatra/reloader'
require 'sinatra/activerecord'
require 'sinatra/activerecord/rake'
确保
require 'rake'
之前
require 'sinatra/activerecord\rake'