I have a note class that belongs to a user (ie a user can create many notes).
clip from my notes controller
class NotesController < ApplicationControl
You can also use Jbuilder(https://github.com/rails/jbuilder) to response with data very flexible.
@notes = Note.includes(:user).order("created_at DESC")
and in your index.json.jbuilder file, you can
json.extract! @note json.username @note.user.username