Different (both bad) output for render and respond custom gson

69 views Asked by At

I'm using Grails 3.2.3 and created own views in grails-app/views/training:

in _short-training.gson

import com.example.trainings.Training

model {
    Training training
}

json g.render(training, [includes:['id', 'name']])

in short-index.gson

import com.example.trainings.Training

model {
    Iterable<Training> trainingList
}

json tmpl.'short-training'(trainingList ?: [])

in controller I tried two different approaches but noone of them is working. Both return 200 status but instead of 6 training instances I received:

    render(view: "short-index", model: [trainingList: section.trainings])

[null,null,null,null,null,null]

    respond section.trainings, [status: OK, view:"short-index"]

[]

it seems that trainings are visible in short-index.gson while used render but are not passed further. respond do not pass trainings at all. what am I missing?

1

There are 1 answers

1
Graeme Rocher On BEST ANSWER

Replace

json tmpl.'short-training'(trainingList ?: [])

With

json tmpl.'short-training'("training", trainingList ?: []) 

The first argument can be used to specify the model variable name