Sha256: 3edd2ea29381ba7e24f0f375904422d4223a8885e2238e618668d7e7ac9eb615
Contents?: true
Size: 1.54 KB
Versions: 1
Compression:
Stored size: 1.54 KB
Contents
config.after_initialize do class ::ActionController::Base alias_method :original_render, :render def render(*args, &block) if args.length == 1 && args[0].kind_of?(Hash) hash = args.first case hash[:rgviz] when nil then original_render *args, &block else model = hash[:rgviz] query = params[:tq] tqx = params[:tqx] || '' pieces = tqx.split ';' reqId = '0' version = '0.6' responseHandler = 'google.visualization.Query.setResponse' pieces.each do |p| key_value = p.split ':' if key_value.length == 2 case key_value[0] when 'reqId' reqId = key_value[1] when 'version' version = key_value[1] when 'responseHandler' responseHandler = key_value[1] end end end begin executor = Rgviz::Executor.new model, Rgviz::Parser.new(query).parse table = executor.execute original_render :text => "#{responseHandler}({reqId:'#{reqId}',status:'ok',version:'#{version}',table:#{table.to_json}});" rescue ParseException => e msg = e.message.gsub("'", "\\'") original_render :text => "#{responseHandler}({reqId:'#{reqId}',status:'error',version:'#{version}',errors:[{reason:'invalid_query', message:'#{msg}'}]});" end end else original_render *args, &block end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rgviz-rails-0.7 | rails/init.rb |