0
0

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 3 years have passed since last update.

【rails】カラムを確認する簡単な方法

Posted at
rails c

でコンソールを開く。

User.column_names

でカラムを確認する。
すると下記のように、他の不要な情報を取得せず現在作成しているカラム名だけを取得し確認することができる。

[1] pry(main)> User.column_names
=> ["id",
 "email",
 "encrypted_password",
 "reset_password_token",
 "reset_password_sent_at",
 "remember_created_at",
 "created_at",
 "updated_at"]

ちなみにUser.columns.map(&:name)でも同様の確認が可能です。

[2] pry(main)> User.columns.map(&:name)
=> ["id",
 "email",
 "encrypted_password",
 "reset_password_token",
 "reset_password_sent_at",
 "remember_created_at",
 "created_at",
 "updated_at"]

しかしこれだと記述が長いので、User column_namesで確認するのが良いかと思われます◯

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?