【问题标题】:Why is there a wrong number of arguments error when using redirect_to in Rails 4.2?为什么在 Rails 4.2 中使用 redirect_to 时参数数量错误?
【发布时间】:2019-03-04 06:42:42
【问题描述】:

在一个应用程序的Rails 4.1.1版本中,我在articles_controller中有以下create方法:

def create
  @article = Article.new(article_params)
  authorize @article
  if @article.save
    flash[:notice] = "Successfully created article."
    redirect_to edit_article_path(@article)
  else
    render :new
  end
end

但是,更新到 Rails 4.2 后,尝试重定向时会出现以下错误:

wrong number of arguments (2 for 1)

为什么会出现这个错误,如何解决?

【问题讨论】:

  • 在最近一次 4.2 升级后我实际上遇到了这个问题,但我没有使用 turbolinks。

标签: ruby-on-rails ruby-on-rails-4.2


【解决方案1】:

该问题是由包含过时版本的 Turbolinks (2.2.2) 的 Gemfile 引起的。我通过将 Turbolinks 升级到 2.5.3 版解决了这个问题。

在 Gemfile 中:

gem 'turbolinks', '~> 2.5.3'

【讨论】:

  • 哇。这个真的很难找到,我花了大约 2 个小时不知道如何处理这个错误。非常感谢您的回答。
  • 我在升级到 4.2 时遇到了这个问题,我所有的 assert_redirected_to 测试突然都失败了。我也在这里待了大约 3 个小时,所以感谢 OP 回答你自己的问题。
  • 幸运的是,我在几分钟内就找到了。
猜你喜欢
  • 1970-01-01
  • 2010-11-28
  • 2010-10-29
  • 2015-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多