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 1 year has passed since last update.

Rails7 - rails console ( pry-rails ) で何故かActiveModelのデータ(インスタンス情報)が表示されない

Posted at

問題

昔のバージョンではこれで色々データが表示されてたはず

User.last
=> #<User:0x4420>

解決

とりあえずattributesで表示できた

User.last.attributes
# => {"id"=>3,
#  "email"=>"example@example.com",
#  "remember_created_at"=>nil}

その他

to_json も試したが何故か引数が必須になっている
only 指定は動くが except 指定が動かない

User.last.to_json(only: [:id])
# => "{\"id\":3}"
User.last.to_json(except: [:id])

#  ArgumentError: wrong number of arguments (given 0, expected 1)

環境

Rails 7.0.4

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

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?