解决方法
每个Sinatra路由都可以在典型的MVC设置中被视为自己的控制器.例如:
require 'sinatra' require 'json' get "/foo" do # This might take many lines of excellent code to form your data @data = some_complex_array_hash_combo haml :foo end
然后在foo.haml:
:javascript var data = #{@data.to_json};