Note that there are some explanatory texts on larger screens.

plurals
  1. POUndefined method `to_i' for Hash
    text
    copied!<p>I am trying to make a subdomain router for my Rack app but I ran into a problem. Here is my config.ru code:</p> <pre><code>require './controllers/subdomain' require './controllers/www' set :root, './' run Example::Subdomain.new({ :www =&gt; Sinatra::Application }) </code></pre> <p>and here is my subdomain.rb code:</p> <pre><code>module Example class Subdomain def initialize(map = {}) @map = map end def call(env) @map.each do |subdomain, app| if env['HTTP_HOST'].split('.').first.eql?(subdomain) app.call(env) end end end end end </code></pre> <p>When I run this I get the following error:</p> <pre><code>NoMethodError: undefined method `to_i' for {:www=&gt;Sinatra::Application}:Hash /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/lint.rb:555:in `check_status' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/lint.rb:19:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/lint.rb:19:in `assert' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/lint.rb:555:in `check_status' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/lint.rb:51:in `_call' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/lint.rb:37:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/showexceptions.rb:24:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call_without_check' /Library/Ruby/Gems/1.8/gems/sinatra-1.3.6/lib/sinatra/base.rb:161:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/chunked.rb:43:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call' /Library/Ruby/Gems/1.8/gems/thin-1.5.0/lib/thin/connection.rb:81:in `pre_process' /Library/Ruby/Gems/1.8/gems/thin-1.5.0/lib/thin/connection.rb:79:in `catch' /Library/Ruby/Gems/1.8/gems/thin-1.5.0/lib/thin/connection.rb:79:in `pre_process' /Library/Ruby/Gems/1.8/gems/thin-1.5.0/lib/thin/connection.rb:54:in `process' /Library/Ruby/Gems/1.8/gems/thin-1.5.0/lib/thin/connection.rb:39:in `receive_data' /Library/Ruby/Gems/1.8/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine' /Library/Ruby/Gems/1.8/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run' /Library/Ruby/Gems/1.8/gems/thin-1.5.0/lib/thin/backends/base.rb:63:in `start' /Library/Ruby/Gems/1.8/gems/thin-1.5.0/lib/thin/server.rb:159:in `start' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/handler/thin.rb:16:in `run' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/server.rb:264:in `start' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/lib/rack/server.rb:141:in `start' /Library/Ruby/Gems/1.8/gems/rack-1.5.2/bin/rackup:4 /usr/bin/rackup:19:in `load' /usr/bin/rackup:19 -e:1:in `load' -e:1 </code></pre> <p>Does anyone have any idea why this is happening instead of running the <code>app.call(env)</code>?</p> <p>This is a screenshot of the error: <a href="http://i46.tinypic.com/3538is6.jpg" rel="nofollow">http://i46.tinypic.com/3538is6.jpg</a></p> <p>Also this code works, but it doesn't abide by the subdomain rule tho:</p> <pre><code>module Example class Subdomain def initialize(map = {}) @map = map end def call(env) @map.each do |subdomain, app| return app.call(env) end end end end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload