uninitialized constant Rack::Cors
See original GitHub issueI’m having this issue when running a rails 3.2.12 app, it is running with unicorn on production environment
Here is the unicorn log.
/home/deploy/applications/wecul-api/releases/20130606154224/config/application.rb:72:in `<class:Application>'
:
uninitialized constant Rack::Cors
(
NameError
)
from /home/deploy/applications/wecul-api/releases/20130606154224/config/application.rb:12:in `<module:PeepoltvApi>'
from /home/deploy/applications/wecul-api/releases/20130606154224/config/application.rb:11:in `<top (required)>'
from /home/deploy/applications/wecul-api/releases/20130606154224/config/environment.rb:2:in `require'
from /home/deploy/applications/wecul-api/releases/20130606154224/config/environment.rb:2:in `<top (required)>'
from config.ru:4:in `require'
from config.ru:4:in `block in <main>'
from /home/deploy/applications/wecul-api/shared/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
from /home/deploy/applications/wecul-api/shared/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
from config.ru:1:in `new'
from config.ru:1:in `<main>'
from /home/deploy/applications/wecul-api/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn.rb:44:in `eval'
from /home/deploy/applications/wecul-api/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn.rb:44:in `block in builder'
from /home/deploy/applications/wecul-api/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:722:in `call'
from /home/deploy/applications/wecul-api/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:722:in `build_app!'
from /home/deploy/applications/wecul-api/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:140:in `start'
from /home/deploy/applications/wecul-api/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/bin/unicorn:126:in `<top (required)>'
from bin/unicorn:16:in `load'
from bin/unicorn:16:in `<main>'
E, [2013-06-06T21:20:28.718097 #7506] ERROR -- : reaped #<Process::Status: pid 30554 exit 1> exec()-ed
In my Gemfile
I’ve added
gem 'rack-cors', :require => 'rack/cors'
In my config/application.rb
I’ve added
config.middleware.use Rack::Cors do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :delete, :put, :options]
end
end
I’d already tryied
- Adding
require 'rack/cors'
in my `config/application.rb’ - I’ve tryied this in the rails console with this output
Loading production environment (Rails 3.2.12)
irb(main):001:0> Rack::Cors
=> Rack::Cors
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:17 (7 by maintainers)
Top Results From Across the Web
Rails 6, Heroku: NameError: uninitialized constant Rack::Cors
I'm trying to deploy my API to Heroku but it keeps giving me this error NameError: uninitialized constant Rack::Cors.
Read more >Further Exploration with CORS - LearnHowToProgram.com
Our Rails application automatically uses rack-cors middleware to handle CORS. ... you'll get an uninitialized constant error.
Read more >Developers - uninitialized constant Rack::Cors - - Bountysource
I'm having this issue when running a rails 3.2.12 app, it is running with unicorn on production environment ...
Read more >[Solved]-Rails 6, Heroku: NameError: uninitialized constant Rack
Okay, I solved the issue guys, in the build logs you can see the following: Gems in the groups 'development' and 'test' were...
Read more >hanami/chat - Gitter
but get NameError: uninitialized constant Rack::Cors. If I put require rack , I still get that error. If I put require rack/cors ,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You just need to un-comment the Rack CORS gem in your Gemfile (gemfile.rb)
# gemfile.rb
gem 'rack-cors'
And then run the code below to install the gem
bundle install
And also ensure that your cors initializer (cors.rb) is set this way # config/initializers/cors.rb
Setting origins to ‘*’ should be alright for development, but keep in mind that if you deploy to production you’ll want to change this value to match your front-end’s URI for security reasons.
Hope this helps
@akinnunen @mcka1n I encountered the following issue after adding requires into application.rb. Development works but it failed to push to Heroku Please advise.
LoadError: cannot load such file -- rack/cors