LoginSignup
2
4

More than 5 years have passed since last update.

ransack+simple_formでカラムがNULLのものを絞り込むための記述

Last updated at Posted at 2016-09-04

たとえば、user_idNULLのものを検索するチェックボックスを作る場合の実装方法です。チェックボックスにチェックを入れたら、NULLのものに絞り込み、チェックが入っていない場合は、NULLのものNOT NULLのもの両方を検索します。

= f.input :user_id_null, as: :boolean, include_hidden: false

[要注意] このinclude_hidden: falseがミソで、これがついていないとチェックボックスにチェックを入れずに送信すると、NOT NULLだけに絞りこまれてしまいます。デフォルトで絞りこまない仕様になってないのでご注意を。

ちなみに、これが使えるのはsimple_formのバージョン3.3.0からです!

↑の変更が3.3.0から追加されました。

2
4
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
2
4