8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Arel::Nodes::NamedFunctionの引数はArel::Nodes.build_quotedで処理しましょう

Posted at

ransacker_translatorというgemを作っているのですが、そのときに不具合に遭遇したのでメモっておきます。

Railsを4.2にバージョンアップしたところ、Ransackで独自に作った検索条件のところでテストが落ちてしまいました。

RuntimeError: unsupported: String

原因は、Arel::Nodes::NamedFunctionの引数の配列に素の文字列を渡していたことにありました。
それらを全てArel::Nodes.build_quotedで処理する必要があるようです。

参考URL: Regression with NamedFunction and InfixOperation

修正前のコード

Arel::Nodes::NamedFunction.new(db_function_name, args)

修正後のコード

Arel::Nodes::NamedFunction.new(db_function_name, args.map { |it| Arel::Nodes.build_quoted(it) })
8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?