Skip to content

Instantly share code, notes, and snippets.

@tiegz
Created May 7, 2012 20:28
Show Gist options
  • Save tiegz/2630194 to your computer and use it in GitHub Desktop.
Save tiegz/2630194 to your computer and use it in GitHub Desktop.
Visualizing ARel ASTs from your ActiveRecord queries
# Add the graphiz gem to your Gemfile
gem "ruby-graphviz"
# And in the rails console, try the following:
require 'graphviz'
arel = User.where(:name => "Sadako Yamamura").where(:location => "Tokyo").limit(1).arel
graph = GraphViz.parse_string(arel.to_dot)
graph.output(:png => "user_query.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment