2016-01-21 43 views
0

直到昨天,我可以使用我的滑轨应用程序根目录下的rails c快捷方式启动滑轨控制台。该应用程序被设置为仅用于API角色前端的应用程序。当我试图昨晚启动它,我得到了以下错误:起始滑轨控制台抛出错误

Running via Spring preloader in process 5967 
/Users/Andrew/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.5/lib/action_dispatch/middleware/stack.rb:90:in `insert': can't modify frozen Array (RuntimeError) 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.5/lib/action_dispatch/middleware/stack.rb:90:in `insert' 
    from /Users/Andrew/sites/mine/K24/api/config/application.rb:15:in `<class:Application>' 
    from /Users/Andrew/sites/mine/K24/api/config/application.rb:10:in `<module:Api>' 
    from /Users/Andrew/sites/mine/K24/api/config/application.rb:9:in `<top (required)>' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:141:in `require_application_and_environment!' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:67:in `console' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require' 
    from /Users/Andrew/sites/mine/K24/api/bin/rails:9:in `<top (required)>' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency' 
    from /Users/Andrew/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load' 
    from /Users/Andrew/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' 
    from /Users/Andrew/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' 
    from -e:1:in `<main>' 

根据这个错误它在抱怨在application.rb file我跑的文件夹上的差异,发现差异只是下面的”问题

  1. application.rb我只能除去
  2. 在routes文件我增加了一些新航线的评论:

    后 “更新”,以“的帖子#更新”

我试图做修复此如下:

  • 停止和重新启动春季
  • 删除了额外的路线(即所述更新路由)
  • 按本post我尝试添加行成application.rb文件:

    (注 - 这不会格式化为出于某种原因代码块) config.autoload_paths + = %W {#{} config.root/lib目录}

任何建议,为什么发生这种情况?

编辑

公示application.rb文件的内容:

require File.expand_path('../boot', __FILE__) 

require 'rails/all' 

# Require the gems listed in Gemfile, including any gems 
# you've limited to :test, :development, or :production. 
Bundler.require(*Rails.groups) 

module Api 
    class Application < Rails::Application 
    # Settings in config/environments/* take precedence over those specified here. 
    # Application configuration should go into files in config/initializers 
    # -- all .rb files in that directory are automatically loaded. 

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 
    # config.time_zone = 'Central Time (US & Canada)' 

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 
    # config.i18n.default_locale = :de 

    config.api_only = true 
    # Do not swallow errors in after_commit/after_rollback callbacks. 
    config.active_record.raise_in_transactional_callbacks = true 

    config.middleware.insert_before 0, "Rack::Cors", :debug => true, :logger => (-> { Rails.logger }) do 
     allow do 
     origins '*' 

     resource '/cors', 
      :headers => :any, 
      :methods => [:post] 

     resource '*', 
      :headers => :any, 
      :methods => [:get, :post, :delete, :put, :options, :head], 
      :max_age => 0 
     end 
    end 
    end 
end 
+0

你可以发布你的'application.rb'文件的内容吗? – sjagr

+0

@sjagr看到我上面的编辑 – Katana24

回答

0

我的编辑巴尔码的回答似乎并没有被批准,但我给了她一个+1,因为它使我下面的答案。

实际的问题是开发环境下的gem spring实际上是导致问题的原因。评论t出让我可以访问rails控制台 - 这是修复上述问题,但是,这意味着该应用程序抛出另一个错误,因为它can't find a helper

所以我现在在做的事情实际上是根据需要在两者之间切换 - 并不理想,但这确实意味着我可以继续发展。

1

我认为这个问题是因为该行的:Bundler.require(*Rails.groups)

启动控制台之前,所述捆绑试图通过这条线发射你的宝石。 检查你的Gemfile。你有没有定义任何组(测试,开发等)?

您可能想用这个代替尝试:Bundler.require(:default, :assets, Rails.env)

+0

我尝试了你的建议,但没有奏效。不过,我按照您的建议检查了宝石文件,并定义了几个环境。发展中有一个春天的宝石 - 我评论它,它运行良好。 – Katana24