2013-02-10 104 views
0

我使用D3.js的一個示例,它使用d3.json函數在Rails中加載flare.json。 我已將flare.json文件放入與我的視圖相同的文件夾中。當我加載頁面時出現此錯誤:沒有路線匹配[GET]「/flare.json」

ActionController::RoutingError (No route matches [GET] "/flare.json"): 

如何告訴rails將此請求路由到flare.json文件?

這是代碼,瓶坯負載:

d3.json("flare.json", function(error, root) { 
    var node = svg.selectAll(".node") 
     .data(bubble.nodes(classes(root)) 
     .filter(function(d) { return !d.children; })) 
    .enter().append("g") 
     .attr("class", "node") 
     .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); 

    node.append("title") 
     .text(function(d) { return d.className + ": " + format(d.value); }); 

    node.append("circle") 
     .attr("r", function(d) { return d.r; }) 
     .style("fill", function(d) { return color(d.packageName); }); 

    node.append("text") 
     .attr("dy", ".3em") 
     .style("text-anchor", "middle") 
     .text(function(d) { return d.className.substring(0, d.r/3); }); 
}); 

謝謝!

回答

0

在路由添加條目:

match "flare" => "some_controller#index" 

並在控制器:

def index 
    respond_to do |format| 
    format.json { render :json => { 1 => "First", 2 => "Second"} } 
    end 
end