# Come aggiungere i dati dell'utente al serializzatore del post?

**URL:** <https://meta.discourse.org/t/how-to-add-user-data-to-the-post-serializer/143523>\
**Category:** Development\
**Created:** [6 Marzo 2020, 3:48pm UTC](https://meta.discourse.org/t/how-to-add-user-data-to-the-post-serializer/143523 "2020-03-06T15:48:35Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bennett](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bennett/32/171668_2.png) [@bennett](https://meta.discourse.org/u/bennett)\
**Post date:** [6 Marzo 2020, 7:35pm UTC](https://meta.discourse.org/t/how-to-add-user-data-to-the-post-serializer/143523/2 "2020-03-06T19:35:40Z")

</div>

Penso di averlo fatto funzionare, almeno in una misura accettabile. Non sono riuscito a capire come aggiungere il campo `website` al serializzatore dei post, e sembra che non possa aggiungere un campo chiamato `user_custom_fields` (forse è riservato). Sono riuscito ad aggiungere un campo `user_extra_fields` che contiene tutti i `user.custom_fields`. Poi nei miei componenti del tema posso accedere a quei campi quando necessario (anche se è un po’ strano dover usare un campo chiamato `user_field_1`).

Quanto segue ha fatto ciò di cui avevo bisogno:

```
after_initialize do
  add_to_serializer(:post, :user_extra_fields, false) {
    return object.user.custom_fields
  }
end

```

---

_[View the full topic](https://meta.discourse.org/t/how-to-add-user-data-to-the-post-serializer/143523)._
