We are upgrading our Rails app from 4.1 to 4.2.
While this code works great in 4.0 and 4.1:
admin_root_url(:subdomain => 'www')
When I try it on 4.2.3 I get this error:
ArgumentError: wrong number of arguments (3 for 1..2)
I checked it several time in console, running this code:
include Rails.application.routes.url_helpers
default_url_options[:host] = "localhost"
root_url
Our Gemfile looks like this:
source 'https://rubygems.org'
ruby "2.1.2"
gem 'rails', '4.2.4'
gem 'rake', "~> 10.2.2"
group :development do
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Generates model and controller UML diagrams
gem 'railroady'
gem 'bullet'
gem 'web-console', '~> 2.0'
end
group :staging, :production do
gem 'pg'
gem 'rails_12factor'
gem 'newrelic_rpm'
end
gem 'sass-rails', '~> 4.0.0'
gem 'less-rails-bootstrap'
gem 'uglifier', '>= 1.3.0'
gem 'yui-compressor'
gem 'coffee-rails', '~> 4.0.0'
gem 'therubyracer', platforms: :ruby
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
gem 'simple_form', '~> 3.1.0'
gem "paperclip", "~> 4.2"
gem 'aws-sdk'
gem 'devise', '~> 3.5.2'
gem "cancan"
gem 'friendly_id', '~> 5.0.2'
gem 'pusher', '~> 0.14.5'
gem "configurable_engine", :path => "vendor/gems/configurable_engine"
gem 'backbone-rails'
gem 'marionette-rails'
gem "breadcrumbs_on_rails"
gem 'subdomain-fu', :git => "git://github.com/mbleigh/subdomain-fu.git"
gem 'bitly'
gem 'social-share-button', '~> 0.1.8'
gem 'momentjs-rails', '~> 2.5.0'
gem 'bootstrap3-datetimepicker-rails', '~> 3.0.0'
gem 'rails_autolink'
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
gem "twitter"
gem 'unicorn'
gem 'i18n-js', '>= 3.0.0.rc11'
gem 'sitemap_generator'
gem 'will_paginate-bootstrap'
group :test, :development, :staging do
gem 'populator'
gem 'faker'
end
gem "jquery-fileupload-rails"
gem 'rails-timeago', '~> 2.0'
gem 'font-awesome-rails'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'jquery-minicolors-rails'
gem 'htmlentities', '~> 4.3.2'
gem 'sanitize'
gem 'nokogiri'
gem 'dalli'
gem 'kgio', '~> 2.9.3'
gem 'useragent'
gem "fog", "~>1.20"#, require: "fog/aws/storage"
gem 'asset_sync'
gem 'responders', '~> 2.0'
gem 'rails-deprecated_sanitizer'
================ edit ===============
Stack-trace in console:
ArgumentError: wrong number of arguments (3 for 1..2)
from /home/guy/.rvm/gems/ruby-2.1.2/bundler/gems/subdomain-fu-3752799a02c0/lib/subdomain_fu/url_rewriter.rb:6:in `url_for_with_subdomains'
from /home/guy/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:282:in `call'
from /home/guy/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:225:in `call'
from /home/guy/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:347:in `block (2 levels) in define_url_helper'
from (irb):3
from /home/guy/.rvm/gems/ruby-2.1.2/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start'
from /home/guy/.rvm/gems/ruby-2.1.2/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start'
from /home/guy/.rvm/gems/ruby-2.1.2/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/guy/.rvm/gems/ruby-2.1.2/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/guy/.rvm/gems/ruby-2.1.2/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
================ edit (2) ===============
I dived into the code and saw that the line in /gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb (282) that raises the error is that:
t._routes.url_for(hash, route_name, url_strategy)
While the url_for
function signature in url_rewriter is:
def url_for_with_subdomains(options, path_segments=nil)
Looks like I need to update something, but I don’t know what.
================ edit (3) ===============
Just to be sure that it has nothing to do with my routes.rb
file, I cleaned it and left it like that:
MyApp::Application.routes.draw do
root 'pages#index', :constraints => {:subdomain => /www|$^/}
end
As expected, still have the same error.
4
Answers
Had the same problem, the solution was instead of using:
I din’t included and added url_helpers to a variable, like this:
I had exactly same problem and at the end in my case
t._routes.url_for(hash, route_name, url_strategy)
called
url_for_with_secure_option
frombartt-ssl_requirement
gem.Since we don’t need
bartt-ssl_requirement
gem anymore in our case solution was to simply removebartt-ssl_requirement
gem.Try to remove
subdomain-fu
and use Rails4request.subdomain
when needed.In case you get that error in the console, because you use a helper that uses URL helpers: