0

我正在使用一个示例,D3.js该示例使用该函数在 Railsd3.json中加载。flare.json我的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); });
});

谢谢!

4

1 回答 1

0

在路线中添加条目:

match "flare" => "some_controller#index"

在控制器中:

def index
  respond_to do |format|
    format.json { render :json => { 1 => "First", 2 => "Second"} }
  end
end
于 2013-02-11T21:51:56.087 回答