我们正在将我们的 Rails 应用程序从 4.1 升级到 4.2。
虽然此代码在 4.0 和 4.1 中运行良好:
admin_root_url(:subdomain => 'www')
当我在 4.2.3 上尝试时,我收到此错误:
ArgumentError: wrong number of arguments (3 for 1..2)
我在控制台中检查了几次,运行以下代码:
include Rails.application.routes.url_helpers
default_url_options[:host] = "localhost"
root_url
我们的 Gemfile 看起来像这样:
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'
================编辑===============
控制台中的堆栈跟踪:
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)=================
我跳入了代码中,看到了 /gems /activepack中的行引发错误的-4.2.4/lib/action_dispatch/routing/route_set.rb(282)是:
t._routes.url_for(hash, route_name, url_strategy)
而url_rewriterurl_for
中的函数签名是:
def url_for_with_subdomains(options, path_segments=nil)
看起来我需要更新一些东西,但我不知道是什么。
================编辑(3)===============只是为了确保它与我的文件
无关,我routes.rb
清理它并像这样离开它:
MyApp::Application.routes.draw do
root 'pages#index', :constraints => {:subdomain => /www|$^/}
end
正如预期的那样,仍然有同样的错误。