Я прохожу учебник по развертыванию моего приложения React / Rails на Heroku. Я ничего не изменил в config/initializers/cors.rb
, но вдруг Rails выдает NO Method error
из этого файла. Я пытался bundle install
. Я также изменил свой файл cors
на подстановочный знак, чтобы быть уверенным (это был конкретный адрес моего приложения Heroku), но все равно получал следующие ошибки:
Running rake db:migrate on ⬢ faunagram-api... up, run.4653 (
Free)
rake aborted!
NameError: undefined local variable or method `config' for main:Object
/app/config/initializers/cors.rb:10:in `<main>'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `block in load'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/engine.rb:657:in `block in load_config_initializer'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/notifications.rb:170:in `instrument'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/engine.rb:656:in `load_config_initializer'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/engine.rb:614:in `block (2 levels) in <class:Engine>'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/engine.rb:613:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/engine.rb:613:in `block in <class:Engine>'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `tsort_each_child'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
/app/config/environment.rb:5:in `<main>'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:83:in `register'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/application.rb:337:in `require_environment!'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/app/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)
мой файл Cors:
# Be sure to restart your server when you modify this file.
# Avoid CORS issues when API is called from the frontend app.
# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
# Read more: https://github.com/cyu/rack-cors
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end
# `
# Rails.application.config.middleware.insert_before 0, Rack::Cors do
# allow do
# if Rails.env.development?
# origins ‘*’
# else
# origins [‘https://yourapp.herokuapp.com','http://yourapp.herokuapp.com']
# end
# resource ‘*’,
# headers: :any,
# methods: [:get, :post, :put, :patch, :delete, :options, :head]
# end
# end`
Я не уверен, что изменилось, но я не могу heroku run rake db:migrate