简体   繁体   中英

unable to render more than one partial with jbuilder

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM