2
2

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.

ストロングパラメータでチェックボックスの値を許可する

Last updated at Posted at 2015-04-30

記述に迷ったのでメモがてら。
Strong parameterでチェックボックスのような不特定多数の値を許可する時、
下記のcheck_valように配列で定義してやる必要があります。

      params.require(:test_form).permit(
        :val,
        check_val: []
      )

6/12 追記
画面側もf.checkbox :check_val みたいなヘルパー使用そのままでは展開されないので下記のように直接フィールド名を編集してやります。

      = check_box_tag '[test_form]check_val[]', 1, false
2
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?