3

我们正在将我们的 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

正如预期的那样,仍然有同样的错误。

4

4 回答 4

0

In case you get that error in the console, because you use a helper that uses URL helpers:

class << helper; include Rails.application.routes.url_helpers; end
helper.my_method # \o/
于 2018-12-20T10:41:01.603 回答
0

我有完全相同的问题,最后在我的情况下

t._routes.url_for(hash, route_name, url_strategy)

url_for_with_secure_optionbartt-ssl_requirement宝石调用。

由于在我们的案例中不再需要bartt-ssl_requirementgem,因此我们的解决方案是简单地删除bartt-ssl_requirementgem。

于 2017-05-10T11:06:44.783 回答
0

在需要时尝试删除subdomain-fu并使用 Rails4 request.subdomain

于 2017-06-26T21:00:43.947 回答
0

有同样的问题,解决方案是而不是使用:

include Rails.application.routes.url_helpers

我没有将 url_helpers 添加到变量中,如下所示:

url_helpers = Rails.application.routes.url_helpers
url_helpers.root_url
于 2015-10-16T17:50:54.743 回答