9
1

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.

Railsのコンソールで、モデルのカラム名一覧をシンボル型の配列で取得する

Last updated at Posted at 2019-01-31

カラムが大量にあるときに一括でストロングパラメーターを設定する場合などに、コピペすると便利。
(2/2 修正)scivola様より、改善いたしました。.inspectは、改行を防ぐためです。

コンソール
[1] pry(main)> モデル名.column_names.map(&:to_sym).inspect

#=> "[:id, :user_id, :name, ...]"
9
1
8

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
9
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?