SHARE
TWEET

Untitled

a guest Apr 16th, 2012 10 Never
  1. How to use datamapper to return table entries as a json formatted string?
  2. Hash[Page.all( :fields => [:id, :title] ).map{|p|[p.id,p.title]}].to_json
  3.  
  4. DEBUG (0.000176) SELECT `id`, `title` FROM `pages` ORDER BY `id`
  5. > {"1":"page A","2":"page B"}
  6.        
  7. Page.all( :fields => [:title] ).map(&:title).to_json
  8.  
  9. DEBUG (0.000038) SELECT `title` FROM `pages` ORDER BY `id`
  10. > ["page A","page B"]
RAW Paste Data
Top