Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 16th, 2012  |  syntax: None  |  size: 0.38 KB  |  views: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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"]