I’m looking for a good way to return xml or json from a controller including multiple variables. For example:
def index
@ad = Ad.some_annoying_ad
@map = Map.some_map_for_something
@articles = Articles.trending
respond_with @articles
end
How would I best add the @ad and @map var to the @articles array? I have seen people using the merge function, but I am not sure if that’s what I’m looking for. Just want to know which way is most standard, flexible, DRY. Thanks!
Note: I am aware that respond with will automatically format the results in xml or json depending on the file extension added to the url. Thanks!
Instead of merging @ad, @map, just create create a new hash then put add the arrays to it, like
It just render all the datas with groups.