Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Check for block_given? in initialization #15

merged 1 commit into from

2 participants


This is a very small thing but it confused me at first. I followed the instructions on to configure my Rails app by putting this in my application.rb:

config.middleware.use Rack::Cors do

config.middleware.insert_before Warden::Manager, Rack::Cors

I got an error rack-cors-0.2.7/lib/rack/cors.rb:9:in `initialize': undefined method `arity' for nil:NilClass (NoMethodError) on app startup. It took some debugging in the gem and further reading before I realized this is the wrong way to do it. Chalk it up to my unfamiliarity with Rack. You're supposed to do it like this:

config.middleware.insert_before Warden::Manager, Rack::Cors do

My commit checks for block_given?, which is always a good idea anyway.

I'd also be willing to update the Readme with instructions on how to use Rack::Cors correctly with Devise/Warden. Unless you think that should go into the Devise docs.

@cyu cyu was assigned
@cyu cyu merged commit 13782d9 into cyu:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 3, 2012
  1. @dwbutler
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/rack/cors.rb
10 lib/rack/cors.rb
@@ -6,10 +6,12 @@ def initialize(app, opts={}, &block)
@app = app
@logger = opts[:logger]
- if block.arity == 1
- else
- instance_eval(&block)
+ if block_given?
+ if block.arity == 1
+ else
+ instance_eval(&block)
+ end
Something went wrong with that request. Please try again.