2016-01-21 46 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