Question

I have created a controllers function to get all elements of three different models. As simple as this:

def get_all_data
  @events = Event.all
  @activities = Activity.all
  @places = Place.all
end

Then in get_all_data.json:

json.partial! 'event', collection: @events
json.partial! 'activity', collection: @activities
json.partial! 'place', collection: @places

The problem is it only renders one partial, the last one. Am i missing something? Could this be done in some better way?

Was it helpful?

Solution

Try putting them each in their own members of the JSON structure:

json.event do
  json.partial! 'event', collection: @events
end
json.activity do
  json.partial! 'activity', collection: @activities
end
json.place do
  json.partial! 'place', collection: @places
end

I feel like that should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top