Right now I have my index action set up like this, and I when the games component is rendered it basically receives games.to_json
, I would like to reuse the template I have for GET /games.json
which is specified in views/games/index.json.builder
I tried passing render(template: 'games/index.json')
but I get this error:
Render and/or redirect were called multiple times in this action
def index
@games = Game.all
respond_to do |format|
format.html { render component: 'games', props: { games: @games } }
format.json { render :index }
end
end
On views/games/index.json.jbuilder
json.array! @games do |game|
json.extract! game, :id, :title, :cover_thumbnail
json.url game_url(game, format: :json)
end
If I call GET /games.json
I get something like this:
[
{
"id": 133,
"title": "Final Fantasy VII: Remake",
"coverThumbnail": "url",
"url": "http://localhost:3000/games/133.json"
},
...
]
But when I call GET /games
, the games component receives every single attribute, I want to send only the attributes specified on the jbuilder template