3 つの異なるモデルのすべての要素を取得するコントローラー関数を作成しました。これと同じくらい簡単です:
def get_all_data
@events = Event.all
@activities = Activity.all
@places = Place.all
end
次に get_all_data.json で:
json.partial! 'event', collection: @events
json.partial! 'activity', collection: @activities
json.partial! 'place', collection: @places
問題は、最後の 1 つのパーシャルのみをレンダリングすることです。何か不足していますか?これをもっと良い方法で行うことはできますか?