main:Object 的未定义方法“命名空间"(NoMethodError)-活动记录/rakefile [英] undefined method `namespace' for main:Object (NoMethodError) - active record / rakefile

查看:43
本文介绍了main:Object 的未定义方法“命名空间"(NoMethodError)-活动记录/rakefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个基本的 Sinatra 应用程序.当我进入机架"步骤时,出现错误:

I'm attempting to run a basic Sinatra app. When I get to the 'rackup' step I get an error:

/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:3:in `':main:Object 的未定义方法`命名空间'(NoMethodError)

这似乎是 Rake gem 中的范围问题.我没有找到答案,我不太确定需要修复什么.我确实更新了我所有的宝石,希望这无济于事.这是我可能有贡献的代码......

It seems to be a scope issue in the Rake gem. I've had no luck findding an answer and I'm not quite sure what needs to be fixed. I did update all my gems in hopes that would help to no avail. Here is my code that might be contributing....

    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.感谢您的建议.

So, it looks like sinatra-activerecord not just activerecord. I did try activerecord 3.2.17 that didn't work. Thanks for the suggestions.

推荐答案

在我找到解决方案之前,这占用了我数小时的时间:

this took up hours of my time before I found the solution:

http://aaronlerch.github.io/博客/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

环境.rb

require 'bundler/setup'
require 'rake'
require 'sinatra'
require 'sinatra/reloader'
require 'sinatra/activerecord'
require 'sinatra/activerecord/rake'

确保

需要'rake'

之前

需要'sinatra/activerecord\rake'

这篇关于main:Object 的未定义方法“命名空间"(NoMethodError)-活动记录/rakefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆