在创建类似于使用时的哈希时是否可以包含方法或嵌套属性to_json
?
使用 to_json 时,我可以包含 published_events 方法和一些嵌套方法:
render :json => @venue.to_json(:include => {:published_events => {:methods => :to_param, :include => :occurrences}})
在创建类似项目的哈希时可以这样做吗?
@area_attractions = Venue.find(:all, :conditions => ['attraction = ? AND featured = ?', true, true], :limit => 8)
hash = { :main => @main_features, :local_hotspots => @local_hotspots, :area_attractions => @area_attractions }
编辑:我最终还是将这个散列渲染为 JSON:
render :json => hash.to_json