LoginSignup
0
0

More than 1 year has passed since last update.

【Jbuilder】あるカラムのみ返したい

Posted at
  • @usernameだけ出力したい。
json.user_infos do
  json.user @user.name
end
{
  "user_infos": {
    "name": "kato"
  }
}
  • @userだとid name ageなどがすべて出力されてしまう。
json.user_infos do
  json.user @user
end
{
  "user_infos": {
    "user": {
      "id": 1,
      "name": "kato",
      "age": 20,
      "created_at": "2020-08-23T16:46:01.380+09:00",
      "updated_at": "2021-11-02T18:34:16.043+09:00"
    }
  }
}
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